예제 #1
0
 @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
 public void onPistonExtend(BlockPistonExtendEvent event) {
   ZoneManager manager = m_plugin.getZoneManager();
   if (!manager.zoneExists(event.getBlock().getLocation())) {
     for (Block b : event.getBlocks()) {
       if (manager.zoneExists(b.getLocation())) {
         event.setCancelled(true);
         return;
       } else if (manager.zoneExists(b.getRelative(event.getDirection()).getLocation())) {
         event.setCancelled(true);
         return;
       }
     }
   } else {
     Zone zone = manager.getZone(event.getBlock().getLocation());
     for (Block b : event.getBlocks()) {
       if (manager.zoneExists(b.getLocation())) {
         if (!zone.getName().equals(manager.getZone(b.getLocation()).getName())) {
           event.setCancelled(true);
           return;
         }
       }
     }
   }
 }
예제 #2
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onPlayerMove(PlayerMoveEvent event) {
    ZoneManager manager = m_plugin.getZoneManager();
    Zone fromZone = manager.getZone(event.getFrom());
    Zone toZone = manager.getZone(event.getTo());
    if (toZone != null) {
      if (!toZone.canPlayerMove(event.getPlayer())) {
        Vector direction =
            event.getFrom().toVector().subtract(event.getTo().toVector()).normalize();
        event.getPlayer().setVelocity(direction.multiply(2));
        sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoMove"));
        return;
      }
    }

    if (event.getTo().equals(event.getFrom())) {
      return;
    }

    if ((fromZone == null && toZone != null)
        || (fromZone != null && toZone != null && !fromZone.getName().equals(toZone.getName()))) {
      event.getPlayer().sendMessage(toZone.getEnterMessage());
    } else if ((toZone == null && fromZone != null)
        || (fromZone != null && toZone != null && !toZone.getName().equals(fromZone.getName()))) {
      event.getPlayer().sendMessage(fromZone.getExitMessage());
    }

    if (toZone != null && fromZone != null) {
      if (toZone.getName() == fromZone.getName()) {
        Plot toPlot = toZone.getPlot(event.getTo());
        Plot fromPlot = fromZone.getPlot(event.getFrom());

        if ((fromPlot == null && toPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !fromPlot.getName().equals(toPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow entering plot \u00A7c" + toPlot.getName());
        } else if ((toPlot == null && fromPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !toPlot.getName().equals(fromPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow leaving plot \u00A7c" + fromPlot.getName());
        }
      }
    }
  }
예제 #3
0
  /** Handle teleport messages */
  @EventHandler(ignoreCancelled = true)
  private void onPlayerTeleport(PlayerTeleportEvent event) {
    ZoneManager manager = m_plugin.getZoneManager();
    Zone fromZone = manager.getZone(event.getFrom());
    Zone toZone = manager.getZone(event.getTo());
    if (toZone != null) {
      if (!toZone.canPlayerMove(event.getPlayer())) {
        event.setCancelled(true);
        sendMessageNoSpam(event.getPlayer(), UI.getMessage("NoMove"));
        return;
      }
    }

    if (event.getTo().equals(event.getFrom())) {
      return;
    }

    if ((fromZone == null && toZone != null)
        || (fromZone != null && toZone != null && !fromZone.getName().equals(toZone.getName()))) {
      event.getPlayer().sendMessage(toZone.getEnterMessage());
    } else if ((toZone == null && fromZone != null)
        || (fromZone != null && toZone != null && !toZone.getName().equals(fromZone.getName()))) {
      event.getPlayer().sendMessage(fromZone.getExitMessage());
    }

    if (toZone != null && fromZone != null) {
      if (toZone.getName() == fromZone.getName()) {
        Plot toPlot = toZone.getPlot(event.getTo());
        Plot fromPlot = fromZone.getPlot(event.getFrom());

        if ((fromPlot == null && toPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !fromPlot.getName().equals(toPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow entering plot \u00A7c" + toPlot.getName());
        } else if ((toPlot == null && fromPlot != null)
            || (fromPlot != null
                && toPlot != null
                && !toPlot.getName().equals(fromPlot.getName()))) {
          sendZonePrefix(
              event.getPlayer(), toZone, "\u00A7bNow leaving plot \u00A7c" + fromPlot.getName());
        }
      }
    }
  }
예제 #4
0
 /** Use a customPrefix */
 public void sendZonePrefix(CommandSender sender, Zone zone, String message) {
   sender.sendMessage("[\u00A7c" + zone.getName() + "\u00A7r] " + message);
 }