org.bukkit.event.player.PlayerMoveEvent Java Examples
The following examples show how to use
org.bukkit.event.player.PlayerMoveEvent.
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: 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 #2
Source File: Compat19.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e) { Player p = e.getPlayer(); // Glide options if (!p.hasPermission("redprotect.bypass.glide")) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_glide.allow_elytra) { ItemStack item = p.getInventory().getChestplate(); if (item != null && item.getType().equals(Material.ELYTRA)) { PlayerInventory inv = p.getInventory(); inv.setChestplate(new ItemStack(Material.AIR)); if (inv.firstEmpty() == -1) { p.getWorld().dropItem(p.getLocation(), item); } else { inv.setItem(inv.firstEmpty(), item); } p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 10, 1); RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantequip"); } } } }
Example #3
Source File: Scotopic.java From MineTinker with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onMoveImmune(PlayerMoveEvent event) { if (!this.givesImmunity) return; Player player = event.getPlayer(); if (!player.hasPermission("minetinker.modifiers.scotopic.use")) { return; } ItemStack armor = player.getInventory().getHelmet(); if (armor == null) return; if (!modManager.hasMod(armor, this)) return; if (player.hasPotionEffect(PotionEffectType.BLINDNESS)) { player.removePotionEffect(PotionEffectType.BLINDNESS); ChatWriter.logModifier(player, event, this, armor, "RemoveBlindness"); } }
Example #4
Source File: Webbed.java From MineTinker with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onMove(PlayerMoveEvent event) { if (!this.givesImmunity) return; Player player = event.getPlayer(); if (!player.hasPermission("minetinker.modifiers.webbed.use")) { return; } boolean hasWebbed = false; ItemStack armor = null; for (ItemStack stack : player.getInventory().getArmorContents()) { if (stack == null) continue; if (modManager.hasMod(stack, this)) { hasWebbed = true; armor = stack; break; } } if (!hasWebbed) return; if (player.hasPotionEffect(PotionEffectType.SLOW)) { player.removePotionEffect(PotionEffectType.SLOW); ChatWriter.logModifier(player, event, this, armor, "RemoveEffect"); } }
Example #5
Source File: ChatConvIO.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onWalkAway(PlayerMoveEvent event) { // return if it's someone else if (!event.getPlayer().equals(player)) { return; } // if player passes max distance if (!event.getTo().getWorld().equals(conv.getLocation().getWorld()) || event.getTo() .distance(conv.getLocation()) > Integer.valueOf(Config.getString("config.max_npc_distance"))) { // we can stop the player or end conversation if (conv.isMovementBlock()) { moveBack(event); } else { conv.endConversation(); } } return; }
Example #6
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 #7
Source File: ListenerPlayerJump.java From TabooLib with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onJump(PlayerMoveEvent e) { // 不是飞行 if (!e.getPlayer().isFlying() // 生存或冒险模式 && (e.getPlayer().getGameMode() == GameMode.SURVIVAL || e.getPlayer().getGameMode() == GameMode.ADVENTURE) // 坐标计算 && (e.getFrom().getY() + 0.5D != e.getTo().getY()) && (e.getFrom().getY() + 0.419D < e.getTo().getY()) // 不在冷却 && !cooldown.isCooldown(e.getPlayer().getName())) { new PlayerJumpEvent(e.getPlayer()).call().ifCancelled(() -> { // 返回位置 e.setTo(e.getFrom()); // 重置冷却 cooldown.reset(e.getPlayer().getName()); }); } }
Example #8
Source File: JumpPads.java From HubBasics with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { if (needsPressurePlate(event.getPlayer()) || !isBlockRequired(event.getPlayer())) return; Player player = event.getPlayer(); if (!isEnabledInWorld(player.getWorld())) return; Location loc = player.getLocation().subtract(0, 1, 0); if (loc.getBlock().getType() == getMaterial(player)) { player.setVelocity(calculateVector(player)); if (getSound(player) != null) { player.playSound(player.getLocation(), getSound(player), 1, 1); } if (getEffect(player) != null) { particleEffect.display(getEffect(player), player.getLocation(), 1, 1, 1, 1, 40); } } }
Example #9
Source File: Pickup.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) public void onMove(PlayerMoveEvent event) { if(!isSpawned()) return; MatchPlayer player = match.getPlayer(event.getPlayer()); if(player != null) { CooldownPlayerFacet cooler = player.facet(CooldownPlayerFacet.class); if(player.canInteract() && cooler.isNotCooling(this) && Capsule.fromEndpointsAndRadius(event.getFrom().position(), event.getTo().position(), 0.5) .intersects(Sphere.fromCircumscribedCuboid(entity.get().getBoundingBox())) && data.pickup().query(player).isAllowed()) { cooler.coolFor(this, data.cooldown()); despawn(true); player.facet(KitPlayerFacet.class).applyKit(data.kit(), false); } } }
Example #10
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAllowMovementForAuthedPlayer() { // given given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(false); Player player = mock(Player.class); Location from = new Location(null, 100, 90, 200); Location to = new Location(null, 99, 90, 200); PlayerMoveEvent event = spy(new PlayerMoveEvent(player, from, to)); given(listenerService.shouldCancelEvent(player)).willReturn(false); // when listener.onPlayerMove(event); // then verify(listenerService).shouldCancelEvent(player); verifyNoModifyingCalls(event); }
Example #11
Source File: LivefireBoots.java From ce with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean effect(Event event, final Player player) { final PlayerMoveEvent e = (PlayerMoveEvent) event; final Block b = e.getTo().getBlock(); if(!Tools.checkWorldGuard(e.getTo(), player, "PVP", false)) return false; if(b.getType().equals(Material.AIR)) { b.setType(Material.FIRE); new BukkitRunnable() { @Override public void run() { if(b.getType().equals(Material.FIRE)) { player.getWorld().playEffect(e.getTo(), Effect.EXTINGUISH, 60); b.setType(Material.AIR); } } }.runTaskLater(main, FlameDuration); } return true; }
Example #12
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldCancelEventForDisabledUnauthedMovement() { // given given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(false); Player player = mock(Player.class); World world = mock(World.class); Location from = new Location(world, 200, 70, 200); Location to = new Location(world, 199, 70, 199); PlayerMoveEvent event = spy(new PlayerMoveEvent(player, from, to)); given(listenerService.shouldCancelEvent(player)).willReturn(true); // when listener.onPlayerMove(event); // then verify(listenerService).shouldCancelEvent(player); verify(event).setTo(from); }
Example #13
Source File: PlayerMovementListener.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
/** * Modify the to location of the given event to prevent the movement and * move the player so they are standing on the center of the block at the * from location. */ private static void resetPosition(final PlayerMoveEvent event) { Location newLoc; double yValue = event.getFrom().getY(); if(yValue <= 0 || event instanceof PlayerTeleportEvent) { newLoc = event.getFrom(); } else { newLoc = BlockUtils.center(event.getFrom()).subtract(new Vector(0, 0.5, 0)); if(newLoc.getBlock() != null) { switch(newLoc.getBlock().getType()) { case STEP: case WOOD_STEP: newLoc.add(new Vector(0, 0.5, 0)); break; default: break; } } } newLoc.setPitch(event.getTo().getPitch()); newLoc.setYaw(event.getTo().getYaw()); event.setCancelled(false); event.setTo(newLoc); }
Example #14
Source File: BukkitPlotDenyListener.java From PlotMe-Core with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onPlayerMove(PlayerMoveEvent event) { Location location = BukkitUtil.adapt(event.getTo()); if (manager.isPlotWorld(location)) { if (event.getPlayer().hasPermission(PermissionNames.ADMIN_BYPASSDENY)) { return; } Plot plot = manager.getPlot(location); if (plot != null) { if (plot.getOwnerId().equals(event.getPlayer().getUniqueId())) { return; } if (plot.isDenied(event.getPlayer().getUniqueId())) { event.setTo(event.getFrom()); } } } }
Example #15
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 #16
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 #17
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 #18
Source File: TrailGUIHook.java From SuperVanish with Mozilla Public License 2.0 | 6 votes |
@Override public void onPluginEnable(Plugin plugin) { if (!(plugin instanceof TrailGUI)) { superVanish.log(Level.WARNING, "Failed to hook into TrailGUI. (PluginNotFound)"); return; } PlayerMoveEvent.getHandlerList().unregister(plugin); final Listeners trailGUIListeners = new Listeners((TrailGUI) plugin); plugin.getServer().getPluginManager().registerEvents(new Listener() { @EventHandler public void onPlayerMove(PlayerMoveEvent event) { if (superVanish.getVanishStateMgr() .getOnlineVanishedPlayers().contains( event.getPlayer().getUniqueId())) return; trailGUIListeners.onPlayerMove(event); } }, plugin); }
Example #19
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 #20
Source File: ProximityAlarm.java From CardinalPGM with MIT License | 6 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { Optional<TeamModule> team = Teams.getTeamByPlayer(event.getPlayer()); if (region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector()) && team.isPresent() && !team.get().isObserver() && GameHandler.getGameHandler().getMatch().isRunning()) { for (Player player : Bukkit.getOnlinePlayers()) { if (notify == null) { if (detect.evaluate(player).equals(FilterState.DENY)) { player.sendMessage(ChatColor.RED + message); } } else if (notify.evaluate(player).equals(FilterState.ALLOW)) { player.sendMessage(ChatColor.RED + message); } } RegionModule radius = new CylinderRegion("radius", region.getCenterBlock().getVector(), flareRadius, 1); int flareAmount = new Random().nextInt(6); for (int f = 0; flareAmount > f; f++) { Firework firework = Fireworks.spawnFirework(radius.getRandomPoint().getLocation(), Fireworks.getFireworkEffect(MiscUtil.convertChatColorToColor(Teams.getTeamColorByPlayer(event.getPlayer()))), 1); Fireworks.explodeFirework(firework); } } }
Example #21
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@Test public void shouldAllowMovementWithinRadius() { // given given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(true); given(settings.getProperty(RestrictionSettings.ALLOWED_MOVEMENT_RADIUS)).willReturn(12); World world = mock(World.class); Player player = mock(Player.class); given(player.getWorld()).willReturn(world); Location from = new Location(world, 200, 70, 200); Location to = new Location(world, 199, 69, 201); PlayerMoveEvent event = spy(new PlayerMoveEvent(player, from, to)); given(player.getLocation()).willReturn(from); given(listenerService.shouldCancelEvent(player)).willReturn(true); given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(false); // sqrt(10^2 + 2^2 + 4^2) = 11 < 12 (allowed movement radius) Location spawn = new Location(world, 190, 72, 204); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); // when listener.onPlayerMove(event); // then verify(listenerService).shouldCancelEvent(player); verify(player, never()).teleport(any(Location.class)); verify(spawnLoader).getSpawnLocation(player); verifyNoModifyingCalls(event); }
Example #22
Source File: RegionListener.java From EchoPet with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { Player p = event.getPlayer(); IPet pet = EchoPet.getManager().getPet(p); if (pet != null) { if (!WorldUtil.allowRegion(event.getTo())) { EchoPet.getManager().removePet(pet, true); Lang.sendTo(p, Lang.ENTER_PET_DISABLED_REGION.toString()); } } }
Example #23
Source File: Uncarried.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onEvent(PlayerMoveEvent event) { super.onEvent(event); MatchPlayer player = this.flag.getMatch().getPlayer(event.getPlayer()); if (player == null || !player.canInteract() || player.getBukkit().isDead()) return; if (this.inPickupRange(player.getBukkit().getLocation()) && this.canPickup(player)) { this.pickupFlag(player); } }
Example #24
Source File: PoisonIvy.java From ce with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean effect(Event event, Player player) { if(event instanceof BlockPlaceEvent) { BlockPlaceEvent e = (BlockPlaceEvent) event; e.getBlock().setMetadata("ce.mine", new FixedMetadataValue(main, getOriginalName())); } else if(event instanceof PlayerMoveEvent) { if(!player.hasPotionEffect(PotionEffectType.POISON)) { player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, PoisonDuration, PoisonLevel)); player.sendMessage(ChatColor.DARK_GREEN + "You have touched Poison Ivy!"); } } return false; }
Example #25
Source File: RegionListener.java From SonarPet with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { Player p = event.getPlayer(); IPet pet = EchoPet.getManager().getPet(p); if (pet != null) { if (!WorldUtil.allowRegion(event.getTo())) { EchoPet.getManager().removePet(pet, true); Lang.sendTo(p, Lang.ENTER_PET_DISABLED_REGION.toString()); } } }
Example #26
Source File: Portal.java From CardinalPGM with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerMove(PlayerMoveEvent event) { if (region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector())) { tryTeleport(event.getPlayer(), event.getTo().clone(), destination, 1); } if (this.bidirectional && destination != null && destination.contains(event.getTo().toVector()) && !destination.contains(event.getFrom().toVector())) { tryTeleport(event.getPlayer(), event.getTo().clone(), region, -1); } }
Example #27
Source File: BukkitAFKListenerTest.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
@Test void afkPermissionIsNotCalledMoreThanOnceWhenIgnored() { Player player = mockPlayerWithPermissions(); PlayerMoveEvent event = mockMoveEvent(player); underTest.onMove(event); underTest.onMove(event); verify(player, times(1)).hasPermission(anyString()); }
Example #28
Source File: CreativeModeListener.java From ShopChest with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerMove(PlayerMoveEvent e) { // Cancel any player movement if SelectClickType is set ClickType clickType = ClickType.getPlayerClickType(e.getPlayer()); if (clickType instanceof SelectClickType) e.setCancelled(true); }
Example #29
Source File: EvtRegionBorder.java From Skript with GNU General Public License v3.0 | 5 votes |
static void callEvent(final Region r, final PlayerMoveEvent me, final boolean enter) { final Player p = me.getPlayer(); assert p != null; final RegionBorderEvent e = new RegionBorderEvent(r, p, enter); e.setCancelled(me.isCancelled()); for (final Trigger t : triggers) { if (((EvtRegionBorder) t.getEvent()).applies(e)) t.execute(e); } me.setCancelled(e.isCancelled()); }
Example #30
Source File: Playable.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerMove(PlayerMoveEvent event) { Optional<TeamModule> team = Teams.getTeamByPlayer(event.getPlayer()); if (GameHandler.getGameHandler().getMatch().isRunning() && team.isPresent() && !team.get().isObserver()) { if (region != null) { if (region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector())) { ChatUtil.sendWarningMessage(event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_PLAYABLE_LEAVE)); event.setCancelled(true); } } } }