Java Code Examples for org.bukkit.event.player.PlayerMoveEvent#isCancelled()
The following examples show how to use
org.bukkit.event.player.PlayerMoveEvent#isCancelled() .
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: WarpPowderListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (event.isCancelled() || !Main.isPlayerInGame(player)) { return; } if (event.getFrom().getBlock().equals(event.getTo().getBlock())) { return; } GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (gPlayer.isSpectator) { return; } WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class); if (warpPowder != null) { warpPowder.cancelTeleport(true, true); } }
Example 2
Source File: WarpPowderListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (event.isCancelled() || !Main.isPlayerInGame(player)) { return; } if (event.getFrom().getBlock().equals(event.getTo().getBlock())) { return; } GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (gPlayer.isSpectator) { return; } WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class); if (warpPowder != null) { warpPowder.cancelTeleport(true, true); } }
Example 3
Source File: TrapListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (event.isCancelled() || !Main.isPlayerInGame(player)) { return; } double difX = Math.abs(event.getFrom().getX() - event.getTo().getX()); double difZ = Math.abs(event.getFrom().getZ() - event.getTo().getZ()); if (difX == 0.0 && difZ == 0.0) { return; } GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (game.getStatus() == GameStatus.RUNNING && !gPlayer.isSpectator) { for (SpecialItem special : game.getActivedSpecialItems(Trap.class)) { Trap trapBlock = (Trap) special; if (trapBlock.isPlaced()) { if (game.getTeamOfPlayer(player) != trapBlock.getTeam()) { if (event.getTo().getBlock().getLocation().equals(trapBlock.getLocation())) { trapBlock.process(player, game.getPlayerTeam(gPlayer), false); } } } } } }
Example 4
Source File: TrapListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (event.isCancelled() || !Main.isPlayerInGame(player)) { return; } double difX = Math.abs(event.getFrom().getX() - event.getTo().getX()); double difZ = Math.abs(event.getFrom().getZ() - event.getTo().getZ()); if (difX == 0.0 && difZ == 0.0) { return; } GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (game.getStatus() == GameStatus.RUNNING && !gPlayer.isSpectator) { for (SpecialItem special : game.getActivedSpecialItems(Trap.class)) { Trap trapBlock = (Trap) special; if (trapBlock.isPlaced()) { if (game.getTeamOfPlayer(player) != trapBlock.getTeam()) { if (event.getTo().getBlock().getLocation().equals(trapBlock.getLocation())) { trapBlock.process(player, game.getPlayerTeam(gPlayer), false); } } } } } }
Example 5
Source File: PlayerMovementListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Update the last known location of a player to account for the * given movement event */ private void updateLastToLocation(final PlayerMoveEvent event) { if(event.isCancelled()) { this.lastToLocation.put(event.getPlayer(), event.getEntityFrom()); } else { this.lastToLocation.put(event.getPlayer(), event.getEntityTo()); } }
Example 6
Source File: PlayerMovementListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * 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: SentinelEventHandler.java From Sentinel with MIT License | 5 votes |
/** * Called every time a player moves at all, for use with monitoring if players move into range of an NPC. */ @EventHandler public void onPlayerMovesInRange(PlayerMoveEvent event) { if (event.isCancelled()) { return; } if (event.getTo().toVector().equals(event.getFrom().toVector())) { return; } for (SentinelTrait sentinel : cleanCurrentList()) { sentinel.onPlayerMovesInRange(event); } }
Example 8
Source File: PlayerMovementHandler.java From ClaimChunk with MIT License | 4 votes |
@SuppressWarnings("unused") @EventHandler public void onPlayerMove(PlayerMoveEvent e) { if (e != null && !e.isCancelled() && e.getTo() != null) { // Get the previous and current chunks Chunk prev = e.getFrom().getChunk(); Chunk to = e.getTo().getChunk(); // Make sure the player moved into a new chunk if (prev.getX() != to.getX() || prev.getZ() != to.getZ()) { // If the claim is currently autoclaiming, try to claim this chunk if (AutoClaimHandler.inList(e.getPlayer())) { claimChunk.getCommandHandler().mainHandler.claimChunk(e.getPlayer(), to); return; } ChunkHandler ch = claimChunk.getChunkHandler(); // Check if the previous chunk was already claimed boolean lastClaimed = ch.isClaimed(prev.getWorld(), prev.getX(), prev.getZ()); // Check if the new chunk is already claimed if (ch.isClaimed(to.getWorld(), to.getX(), to.getZ())) { // If the new chunk and the previous chunk were claimed, check if the owners differ if (lastClaimed) { UUID prevOwner = ch.getOwner(prev.getWorld(), prev.getX(), prev.getZ()); UUID newOwner = ch.getOwner(to.getWorld(), to.getX(), to.getZ()); // Only display the new chunk's owner if they differ from the previous chunk's owner if ((prevOwner == null && newOwner == null) || (prevOwner != null && !prevOwner.equals(newOwner))) { showTitle(e.getPlayer(), to); } } else { // Show the player the chunk's owner showTitle(e.getPlayer(), to); } } else { // The player entered an unclaimed chunk from a claimed chunk if (lastClaimed) { UUID lastOwner = ch.getOwner(prev.getWorld(), prev.getX(), prev.getZ()); String name = claimChunk.getPlayerHandler().getChunkName(lastOwner); String msg = (e.getPlayer().getUniqueId().equals(lastOwner) ? claimChunk.getMessages().chunkLeaveSelf : claimChunk.getMessages().chunkLeave) .replace("%%PLAYER%%", ((name == null) ? claimChunk.getMessages().chunkLeaveUnknown : name)); Utils.toPlayer(e.getPlayer(), msg); } } } } }
Example 9
Source File: WarpPowderListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onMove(PlayerMoveEvent mv) { if (mv.isCancelled()) { return; } if (mv.getFrom().getBlock().equals(mv.getTo().getBlock())) { return; } Player player = mv.getPlayer(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } WarpPowder powder = null; for (SpecialItem item : game.getSpecialItems()) { if (!(item instanceof WarpPowder)) { continue; } powder = (WarpPowder) item; if (powder.getPlayer().equals(player)) { break; } powder = null; } if (powder != null) { powder.setStackAmount(powder.getStack().getAmount() + 1); player.updateInventory(); powder.cancelTeleport(true, true); return; } }
Example 10
Source File: TrapListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onMove(PlayerMoveEvent move) { if (move.isCancelled()) { return; } double difX = Math.abs(move.getFrom().getX() - move.getTo().getX()); double difZ = Math.abs(move.getFrom().getZ() - move.getTo().getZ()); if (difX == 0.0 && difZ == 0.0) { return; } Player player = move.getPlayer(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (game.isSpectator(player)) { return; } Trap tmpTrap = new Trap(); if (!move.getTo().getBlock().getType().equals(tmpTrap.getItemMaterial())) { return; } Team team = game.getPlayerTeam(player); if (team == null || game.isSpectator(player)) { return; } // get trapped trap ;) for (SpecialItem item : game.getSpecialItems()) { if (!(item instanceof Trap)) { continue; } Trap trap = (Trap) item; if (!trap.getLocation().equals(player.getLocation().getBlock().getLocation())) { continue; } if (trap.getPlacedTeam() == null) { continue; } if (!trap.getPlacedTeam().equals(team)) { trap.activate(player); return; } } }