Java Code Examples for org.bukkit.event.player.PlayerTeleportEvent#getCause()

The following examples show how to use org.bukkit.event.player.PlayerTeleportEvent#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListenerTeleport.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTeleport(PlayerTeleportEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("teleportation.prevent-teleport")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    PlayerTeleportEvent.TeleportCause cause = e.getCause();
    if(isAllowed(cause)) {
        if(cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL && config.getBoolean("teleportation.restart-timer-for-ender-pearl")) {
            manager.tag(player, null, PlayerPreTagEvent.TagType.UNKNOWN, PlayerPreTagEvent.TagReason.UNKNOWN);
        }
        return;
    }

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.teleportation.block-" + (cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL ? "pearl" : "other"));
    this.plugin.sendMessage(player, message);
}
 
Example 2
Source File: InternalMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Prevent teleporting outside the map */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
  if (event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
    double fromY = event.getFrom().getY();
    double toY = event.getTo().getY();

    if ((fromY >= 0.0D && fromY < 255.0D) && (toY < 0.0D || toY >= 255.0D)) {
      event.setCancelled(true);
    }
  }
}
 
Example 3
Source File: WorldBorderMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
/** Prevent teleporting outside the border */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
  if (event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
    if (WorldBorders.isInsideBorder(event.getFrom())
        && !WorldBorders.isInsideBorder(event.getTo())) {
      event.setCancelled(true);
    }
  }
}
 
Example 4
Source File: InternalMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Prevent teleporting outside the map
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    if(event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
        double fromY = event.getFrom().getY();
        double toY = event.getTo().getY();

        if((fromY >= 0.0D && fromY < 255.0D) && (toY < 0.0D || toY >= 255.0D)) {
            event.setCancelled(true);
        }
    }
}
 
Example 5
Source File: WorldBorderMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Prevent teleporting outside the border
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    if(event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
        if(WorldBorderUtils.isInsideBorder(event.getFrom()) &&
           !WorldBorderUtils.isInsideBorder(event.getTo())) {
            event.setCancelled(true);
        }
    }
}
 
Example 6
Source File: PlayerMovementListener.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Fire a CoarsePlayerMoveEvent that wraps the given event, only if it crosses
 * a block boundary, or the PoseFlags change.
 * @param event         The movement event to potentially wrap
 * @return True if the original event was not cancelled, and a coarse event was fired,
 *         and that coarse event was cancelled. In this case, the wrapped event won't
 *         actually be cancelled, but callers should treat it like it is.
 */
private boolean callCoarsePlayerMove(final PlayerMoveEvent event) {
    // Don't fire coarse events for teleports that are not "in-game"
    // e.g. /jumpto command
    if(event instanceof PlayerTeleportEvent) {
        PlayerTeleportEvent teleportEvent = (PlayerTeleportEvent) event;
        if(teleportEvent.getCause() != TeleportCause.ENDER_PEARL &&
           teleportEvent.getCause() != TeleportCause.UNKNOWN) {
            return false;
        }
    }

    // If the movement does not cross a block boundary, and no PoseFlags changed, we don't care about it
    final EntityLocation from = event.getEntityFrom();
    final EntityLocation to = event.getEntityTo();
    if(from.position().coarseEquals(to.position()) && from.poseFlags().equals(to.poseFlags())) {
        return false;
    }

    // Remember whether the original event was already cancelled
    boolean wasCancelled = event.isCancelled();

    CoarsePlayerMoveEvent generalEvent = new CoarsePlayerMoveEvent(event, event.getPlayer(), from, to);
    this.eventBus.callEvent(generalEvent);

    if(!wasCancelled && generalEvent.isCancelled()) {
        // When a coarse event is cancelled, we have our own logic for resetting the
        // player's position, so we un-cancel the event and instead modify its
        // to location to put the player where we want them.
        resetPosition(event);
        return true;
    } else {
        return false;
    }
}
 
Example 7
Source File: TeleportListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent e){
	if (e.getCause() == TeleportCause.SPECTATE && !GameManager.getGameManager().getConfiguration().getSpectatingTeleport()){
		Player player = e.getPlayer();
		if (!player.hasPermission("uhc-core.commands.teleport-admin")){
			e.setCancelled(true);
			player.sendMessage(Lang.COMMAND_SPECTATING_TELEPORT_ERROR);
		}
	}
}
 
Example 8
Source File: TeleportEvent.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void playerTeleport(PlayerTeleportEvent event) {
    Player p = event.getPlayer();
    int id = GameManager.getInstance().getPlayerGameId(p);
    if(id == -1) return;
    if(GameManager.getInstance().getGame(id).isPlayerActive(p) && event.getCause() == PlayerTeleportEvent.TeleportCause.COMMAND){
        p.sendMessage(ChatColor.RED +" Cannot teleport while ingame!");
        event.setCancelled(true);
    }
}
 
Example 9
Source File: SpectateListener.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {
	final Player player = e.getPlayer();
	final GameMap gameMap = MatchManager.get().getSpectatorMap(player);
	if (gameMap == null || player.hasPermission("sw.opteleport")) {
		return;
	}
	if (e.getCause() != TeleportCause.END_PORTAL) {
		e.setCancelled(true);
	}
}
 
Example 10
Source File: ItemListener.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent e) {
    if (e.getCause() == TeleportCause.ENDER_PEARL && plugin.getConfig().getBoolean("mobSpawning.endermites", true)
            && e.getTo().getWorld().getAllowMonsters()) {
        Random rand = new Random();
        if(rand.nextInt(100) < 5) {//5% probability of spawning
        	EntityEndermite ender = new EntityEndermite(((CraftWorld) e.getFrom().getWorld()).getHandle());
            ender.spawn(e.getFrom());
        }
    }
}
 
Example 11
Source File: Listeners.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
    if (event.getCause() == PlayerTeleportEvent.TeleportCause.UNKNOWN) {
        return;
    }
    Player p = event.getPlayer();
    // The player will either quit, die, or close the inventory at some point
    if (plugin.getInVault().containsKey(p.getUniqueId().toString())) {
        return;
    }
    saveVault(p, p.getOpenInventory().getTopInventory());
}