Esempio n. 1
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());
        }
      }
    }
  }
Esempio n. 2
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());
        }
      }
    }
  }