Ejemplo n.º 1
0
  /**
   * Various corner cases that would cause this check to fail or require special treatment
   *
   * @param player
   * @param data
   * @param from
   * @param to
   * @return
   */
  public boolean shouldBeApplied(
      final Player player, final MovingData data, final Location from, final Location to) {

    if (player.isDead() || player.isInsideVehicle() || data.insideVehicle) return false;

    if (data.wasTeleported) {
      // Remember this location
      data.teleportedTo = from.clone();
      data.wasTeleported = false;
      data.jumpPhase = 0;
    }

    if (data.teleportedTo != null && data.teleportedTo.getWorld().equals(from.getWorld())) {
      // As long as the from-Location doesn't change, the player didn't accept the teleport
      if (data.teleportedTo.distanceSquared(from) < 0.01D) {
        // Event after Teleport ignored
        return false;
      } else {
        // The player finally accepted the teleport with the previous event
        data.teleportedTo = null;
      }
    }

    // If the target is a bed, don't check (going to bed is a kind of mini teleport...)
    if (to.getWorld().getBlockTypeIdAt(to) == Material.BED_BLOCK.getId()) {
      return false;
    }

    return true;
  }
Ejemplo n.º 2
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;
  }