Java Code Examples for org.bukkit.event.player.PlayerMoveEvent#getTo()
The following examples show how to use
org.bukkit.event.player.PlayerMoveEvent#getTo() .
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: UHPluginListener.java From KTP with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent ev) { Location l = ev.getTo(); Integer mapSize = p.getConfig().getInt("map.size"); Integer halfMapSize = (int) Math.floor(mapSize/2); Integer x = l.getBlockX(); Integer z = l.getBlockZ(); Location spawn = ev.getPlayer().getWorld().getSpawnLocation(); Integer limitXInf = spawn.add(-halfMapSize, 0, 0).getBlockX(); spawn = ev.getPlayer().getWorld().getSpawnLocation(); Integer limitXSup = spawn.add(halfMapSize, 0, 0).getBlockX(); spawn = ev.getPlayer().getWorld().getSpawnLocation(); Integer limitZInf = spawn.add(0, 0, -halfMapSize).getBlockZ(); spawn = ev.getPlayer().getWorld().getSpawnLocation(); Integer limitZSup = spawn.add(0, 0, halfMapSize).getBlockZ(); if (x < limitXInf || x > limitXSup || z < limitZInf || z > limitZSup) { ev.setCancelled(true); } }
Example 2
Source File: SignUpdater.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void move(final PlayerMoveEvent event) { Player player = event.getPlayer(); Location to = event.getTo(); Location from = event.getFrom(); Block toBlock = to.getBlock(); Block fromBlock = from.getBlock(); handleLook(player, to); if(PORTAL_MATERIALS.contains(toBlock.getType()) && !PORTAL_MATERIALS.contains(fromBlock.getType())) { nearestSign(event.getTo()).ifPresent( sign -> sign.connector().teleport(player) ); } }
Example 3
Source File: MoveListener.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
/** * Performs region checking * * @param event move event */ private void execute(PlayerMoveEvent event) { Player player = event.getPlayer(); NovaPlayer nPlayer = PlayerManager.getPlayer(player); Location from = event.getFrom(); Location to = event.getTo(); NovaRegion fromRegion = RegionManager.get(from); NovaRegion toRegion = RegionManager.get(to); //entering if((fromRegion == null && toRegion != null && nPlayer.getAtRegion() == null) || (fromRegion != null && toRegion != null && !fromRegion.equals(toRegion))) { plugin.getRegionManager().playerEnteredRegion(player, toRegion); } //exiting if(fromRegion != null && toRegion == null && nPlayer.getAtRegion() != null) { plugin.getRegionManager().playerExitedRegion(player); } }
Example 4
Source File: Transporter.java From AnnihilationPro with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true) public void MoveListeners(PlayerMoveEvent event) { ///block under your feet Block to = event.getTo().getBlock().getRelative(BlockFace.DOWN); if(to.getType() == Material.QUARTZ_ORE) { Location x = event.getTo(); Location y = event.getFrom(); if(x.getBlockX() != y.getBlockX() || x.getBlockY() != y.getBlockY() || x.getBlockZ() != y.getBlockZ()) { AnniPlayer user = AnniPlayer.getPlayer(event.getPlayer().getUniqueId()); UUID owner = getBlocksOwner(to); if(owner != null && user != null) { Teleporter tele = this.teleporters.get(owner); if(tele != null && tele.isLinked() && tele.getOwner().getTeam() == user.getTeam()) { event.getPlayer().sendMessage(ChatColor.AQUA+"This is a teleporter owned by "+ChatColor.WHITE+tele.getOwner().getName()+ChatColor.AQUA+", Sneak to go through it."); } } } } }
Example 5
Source File: MoveEvent.java From MCAuthenticator with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onPlayerMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) { return; } Player player = event.getPlayer(); User u = instance.getCache().get(player.getUniqueId()); if (u != null && u.authenticated()) return; event.setTo(from); }
Example 6
Source File: NoEntryListener.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void onMove(PlayerMoveEvent e) { ICombatLogX plugin = this.expansion.getPlugin(); ICombatManager manager = plugin.getCombatManager(); Player player = e.getPlayer(); if(!manager.isInCombat(player)) return; LivingEntity enemy = manager.getEnemy(player); if(enemy == null) return; Location toLocation = e.getTo(); TagType tagType = (enemy instanceof Player ? TagType.PLAYER : TagType.MOB); NoEntryHandler handler = this.expansion.getNoEntryHandler(); if(!handler.isSafeZone(player, toLocation, tagType)) return; Location fromLocation = e.getFrom(); this.expansion.preventEntry(e, player, fromLocation, toLocation); }
Example 7
Source File: ForceField.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onMove(PlayerMoveEvent e) { if(!isEnabled()) return; Player player = e.getPlayer(); if(canBypass(player)) return; ICombatManager combatManager = this.plugin.getCombatManager(); if(!combatManager.isInCombat(player)) return; Location toLoc = e.getTo(); Location fromLoc = e.getFrom(); if(toLoc == null) return; if(toLoc.getBlock().equals(fromLoc.getBlock())) return; if(isSafe(toLoc, player)) return; updateForceField(player); }
Example 8
Source File: Trade.java From TradePlus with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onMove(PlayerMoveEvent event) { if (cancelled || event.getTo() == null) return; Player player = event.getPlayer(); if (player.equals(player1) || player.equals(player2)) { if (event.getFrom().distanceSquared(event.getTo()) < 0.01) return; if (System.currentTimeMillis() < startTime + 1000) { return; } if (player.equals(player1)) { player.teleport(location1); } else { player.teleport(location2); } } }
Example 9
Source File: BrushListener.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); if ((from.getYaw() != to.getYaw() && from.getPitch() != to.getPitch()) || from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ() || from.getBlockY() != to.getBlockY()) { Player bukkitPlayer = event.getPlayer(); FawePlayer<Object> fp = FawePlayer.wrap(bukkitPlayer); com.sk89q.worldedit.entity.Player player = fp.getPlayer(); LocalSession session = fp.getSession(); Tool tool = session.getTool(player); if (tool != null) { if (tool instanceof MovableTool) { ((MovableTool) tool).move(player); } } } }
Example 10
Source File: Scotopic.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (!player.hasPermission("minetinker.modifiers.scotopic.use")) return; ItemStack helmet = player.getInventory().getHelmet(); if (!modManager.isArmorViable(helmet)) return; int level = modManager.getModLevel(helmet, this); if (level <= 0) return; //cooldown checker Long time = System.currentTimeMillis(); long cooldownTime = (long) (this.cooldownInSeconds * 1000 * Math.pow(1.0 - this.cooldownReductionPerLevel, level - 1)); if (this.cooldownInSeconds > 0) { Long cd = cooldownTracker.get(player.getUniqueId().toString()); if (cd != null) { //was on cooldown if (time - cd > cooldownTime || player.getGameMode() == GameMode.CREATIVE) { cooldownTracker.remove(player.getUniqueId().toString()); } else { return; //still on cooldown } } } Location loc = event.getTo(); byte lightlevel = player.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()).getLightLevel(); if (lightlevel <= this.requiredLightLevel) { int duration = this.durationPerLevel * level; player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, duration, level, false, false, false)); cooldownTracker.put(player.getUniqueId().toString(), time); ChatWriter.logModifier(player, event, this, helmet, String.format("Cooldown(%ds)", cooldownTime / 1000), String.format("LightLevel(%d/%d)", lightlevel, this.requiredLightLevel), String.format("Duration(%d)", duration)); } }
Example 11
Source File: PlayerListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW) public void onPlayerMove(PlayerMoveEvent event) { /* * Abort if we havn't really moved */ if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ() && event.getFrom().getBlockY() == event.getTo().getBlockY()) { return; } /* Test for enchants effecting movement. */ /* TODO can speed be set once? If so we should only calculate speed change when our armor changes. */ setModifiedMovementSpeed(event.getPlayer()); ChunkCoord fromChunk = new ChunkCoord(event.getFrom()); ChunkCoord toChunk = new ChunkCoord(event.getTo()); // Haven't moved chunks. if (fromChunk.equals(toChunk)) { return; } TaskMaster.asyncTask(PlayerChunkNotifyAsyncTask.class.getSimpleName(), new PlayerChunkNotifyAsyncTask(event.getFrom(), event.getTo(), event.getPlayer().getName()), 0); }
Example 12
Source File: WorldGuardEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@EventHandler @SuppressWarnings("unused") public void onPlayerMove(PlayerMoveEvent e) { if (e.getTo() == null || !plugin.getWorldManager().isSkyAssociatedWorld(e.getTo().getWorld())) { return; } String islandNameAt = WorldGuardHandler.getIslandNameAt(e.getTo()); if (islandNameAt == null) { return; } IslandInfo islandInfo = plugin.getIslandInfo(islandNameAt); if (islandInfo == null || islandInfo.getBans().isEmpty()) { return; } Player player = e.getPlayer(); if (!player.isOp() && !player.hasPermission("usb.mod.bypassprotection") && isBlockedFromEntry(player, islandInfo)) { e.setCancelled(true); Location l = e.getTo().clone(); l.subtract(islandInfo.getIslandLocation()); Vector v = new Vector(l.getX(), l.getY(), l.getZ()); v.normalize(); v.multiply(1.5); // Bounce player.setVelocity(v); if (islandInfo.isBanned(player)) { plugin.notifyPlayer(player, tr("\u00a7cBanned:\u00a7e You are banned from this island.")); } else { plugin.notifyPlayer(player, tr("\u00a7cLocked:\u00a7e That island is locked! No entry allowed.")); } } }
Example 13
Source File: CUIListener.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); if ((int) from.getX() >> 2 != (int) to.getX() >> 2 || (int) from.getZ() >> 2 != (int) to.getZ() >> 2 || (int) from.getY() >> 2 != (int) to.getY() >> 2) { FawePlayer<Object> player = FawePlayer.wrap(event.getPlayer()); CUI cui = player.getMeta("CUI"); if (cui instanceof StructureCUI) { StructureCUI sCui = (StructureCUI) cui; sCui.update(); } } }
Example 14
Source File: RenderListener.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); if (from.getBlockX() >> OFFSET != to.getBlockX() >> OFFSET || from.getBlockZ() >> OFFSET != to.getBlockZ() >> OFFSET) { Player player = event.getPlayer(); int currentView = getViewDistance(player); setViewDistance(player, Math.max(currentView - 1, 1)); } }
Example 15
Source File: EvtMoveOn.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public void execute(final @Nullable Listener l, final @Nullable Event event) throws EventException { if (event == null) return; final PlayerMoveEvent e = (PlayerMoveEvent) event; final Location from = e.getFrom(), to = e.getTo(); if (!itemTypeTriggers.isEmpty()) { final Block block = getOnBlock(to); if (block == null || block.getType() == Material.AIR) return; final Material id = block.getType(); final List<Trigger> ts = itemTypeTriggers.get(id); if (ts == null) return; final int y = getBlockY(to.getY(), id); if (to.getWorld().equals(from.getWorld()) && to.getBlockX() == from.getBlockX() && to.getBlockZ() == from.getBlockZ() && y == getBlockY(from.getY(), getOnBlock(from).getType()) && getOnBlock(from).getType() == id) return; SkriptEventHandler.logEventStart(e); triggersLoop: for (final Trigger t : ts) { final EvtMoveOn se = (EvtMoveOn) t.getEvent(); for (final ItemType i : se.types) { if (i.isOfType(block)) { SkriptEventHandler.logTriggerStart(t); t.execute(e); SkriptEventHandler.logTriggerEnd(t); continue triggersLoop; } } } SkriptEventHandler.logEventEnd(); } }
Example 16
Source File: PlayerMovementListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private void handleFrozenPlayers(PlayerMoveEvent e){ UhcPlayer uhcPlayer = playersManager.getUhcPlayer(e.getPlayer()); if (uhcPlayer.isFrozen()){ Location freezeLoc = uhcPlayer.getFreezeLocation(); Location toLoc = e.getTo(); if (toLoc.getBlockX() != freezeLoc.getBlockX() || toLoc.getBlockZ() != freezeLoc.getBlockZ()){ Location newLoc = toLoc.clone(); newLoc.setX(freezeLoc.getBlockX() + .5); newLoc.setZ(freezeLoc.getBlockZ() + .5); e.getPlayer().teleport(newLoc); } } }
Example 17
Source File: Carried.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onEvent(PlayerMoveEvent event) { super.onEvent(event); if (this.isCarrier(event.getPlayer())) { Location playerLoc = event.getTo(); if (this.flag.canDropAt(playerLoc)) { if (this.dropLocations.size() >= DROP_QUEUE_SIZE) this.dropLocations.removeLast(); this.dropLocations.addFirst(playerLoc); } this.checkCapture(event.getTo()); } }
Example 18
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 19
Source File: PlayerListener.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPlayerMove(PlayerMoveEvent event) { if (settings.getProperty(ALLOW_UNAUTHED_MOVEMENT) && settings.getProperty(ALLOWED_MOVEMENT_RADIUS) <= 0) { return; } Location from = event.getFrom(); Location to = event.getTo(); if (to == null) { return; } /* * Limit player X and Z movements to 1 block * Deny player Y+ movements (allows falling) */ if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ() && from.getY() - to.getY() >= 0) { return; } Player player = event.getPlayer(); if (!listenerService.shouldCancelEvent(player)) { return; } if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) { // "cancel" the event event.setTo(event.getFrom()); return; } if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) { return; } Location spawn = spawnLoader.getSpawnLocation(player); if (spawn != null && spawn.getWorld() != null) { if (!player.getWorld().equals(spawn.getWorld())) { player.teleport(spawn); } else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) { player.teleport(spawn); } } }
Example 20
Source File: CEListener.java From ce with GNU Lesser General Public License v3.0 | 3 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void PlayerMoveEvent(PlayerMoveEvent e) { Location from = e.getFrom(); Location to = e.getTo(); if (from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ()) { CEventHandler.handleEvent(e.getPlayer(), e, move); CEventHandler.handleMines(e.getPlayer(), e); } }