Esempio n. 1
0
  /**
   * Call this when a player got successfully teleported with the corresponding event to adjust
   * stored data to the new situation
   *
   * @param event
   */
  public void teleported(PlayerTeleportEvent event) {

    MovingData data = MovingData.get(event.getPlayer());

    // We can enforce a teleport, if that flag is explicitly set (but I'd rather have other plugins
    // not arbitrarily cancel teleport events in the first place...
    if (data.teleportInitializedByMe != null
        && event.isCancelled()
        && enforceTeleport
        && event.getTo().equals(data.teleportInitializedByMe)) {
      event.setCancelled(false);
      data.teleportInitializedByMe = null;
    }

    if (!event.isCancelled()) {
      data.wasTeleported = true;
      data.setBackPoint = event.getTo().clone();
      // data.lastLocation = event.getTo().clone();
    }

    // reset anyway - if another plugin cancelled our teleport it's no use to try and be precise
    data.jumpPhase = 0;
  }
Esempio n. 2
0
  /**
   * Perform actions that were specified in the config file
   *
   * @param event
   * @param action
   * @return
   */
  private Location action(
      Player player,
      Location from,
      Location to,
      Action[] actions,
      int violations,
      MovingData data) {

    Location newToLocation = null;

    if (actions == null) return newToLocation;
    boolean cancelled = false;

    for (Action a : actions) {
      if (a.firstAfter <= violations) {
        if (a.firstAfter == violations || a.repeat) {
          if (a instanceof LogAction) {
            // prepare log message if necessary
            String log =
                String.format(
                    Locale.US,
                    logMessage,
                    player.getName(),
                    from.getWorld().getName(),
                    to.getWorld().getName(),
                    from.getX(),
                    from.getY(),
                    from.getZ(),
                    to.getX(),
                    to.getY(),
                    to.getZ(),
                    Math.abs(from.getX() - to.getX()),
                    to.getY() - from.getY(),
                    Math.abs(from.getZ() - to.getZ()));

            plugin.log(((LogAction) a).level, log);

            // Remember the highest log level we encountered to determine what level the summary log
            // message should have
            if (data.highestLogLevel == null) data.highestLogLevel = Level.ALL;
            if (data.highestLogLevel.intValue() < ((LogAction) a).level.intValue())
              data.highestLogLevel = ((LogAction) a).level;
          } else if (!cancelled && a instanceof CancelAction) {
            // Make a modified copy of the setBackPoint to prevent other plugins from accidentally
            // modifying it
            // and keep the current pitch and yaw (setbacks "feel" better that way). Plus try to
            // adapt the Y-coord
            // to place the player close to ground

            double y = data.setBackPoint.getY();

            // search for the first solid block up to 5 blocks below the setbackpoint and teleport
            // the player there
            int i = 0;
            for (; i < 20; i++) {
              if (playerIsOnGround(data.setBackPoint, -0.5 * i) != MovingData.NONSOLID) {
                break;
              }
            }
            y -= 0.5 * i;

            data.setBackPoint.setY(y);

            // Remember the location we send the player to, to identify teleports that were started
            // by us
            data.teleportInitializedByMe =
                new Location(
                    data.setBackPoint.getWorld(),
                    data.setBackPoint.getX(),
                    y,
                    data.setBackPoint.getZ(),
                    to.getYaw(),
                    to.getPitch());

            newToLocation = data.teleportInitializedByMe;

            cancelled =
                true; // just prevent us from treating more than one "cancel" action, which would
            // make no sense
          } else if (a instanceof CustomAction) plugin.handleCustomAction((CustomAction) a, player);
        }
      }
    }

    return newToLocation;
  }