@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerTeleport(PlayerTeleportEvent event) { final Player player = event.getPlayer(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); // Check absolute value to account for negatives if (Math.abs(event.getTo().getX()) >= MAX_XY_COORD || Math.abs(event.getTo().getZ()) >= MAX_XY_COORD) { event.setCancelled(true); // illegal position, cancel it } if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) { TFM_Util.setFlying(player, true); event.setTo(playerdata.getFreezeLocation()); return; // Don't process adminworld validation } TFM_AdminWorld.getInstance().validateMovement(event); }
@EventHandler(priority = EventPriority.NORMAL) public void onPlayerMove(PlayerMoveEvent event) { final Location from = event.getFrom(); final Location to = event.getTo(); try { if (from.getWorld() == to.getWorld() && from.distanceSquared(to) < (0.0001 * 0.0001)) { // If player just rotated, but didn't move, don't process this event. return; } } catch (IllegalArgumentException ex) { } if (!TFM_AdminWorld.getInstance().validateMovement(event)) { return; } final Player player = event.getPlayer(); final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player); for (Entry<Player, Double> fuckoff : TotalFreedomMod.fuckoffEnabledFor.entrySet()) { Player fuckoffPlayer = fuckoff.getKey(); if (fuckoffPlayer.equals(player) || !fuckoffPlayer.isOnline()) { continue; } double fuckoffRange = fuckoff.getValue(); Location playerLocation = player.getLocation(); Location fuckoffLocation = fuckoffPlayer.getLocation(); double distanceSquared; try { distanceSquared = playerLocation.distanceSquared(fuckoffLocation); } catch (IllegalArgumentException ex) { continue; } if (distanceSquared < (fuckoffRange * fuckoffRange)) { event.setTo( fuckoffLocation .clone() .add( playerLocation .subtract(fuckoffLocation) .toVector() .normalize() .multiply(fuckoffRange * 1.1))); break; } } // Freeze if (!TFM_AdminList.isSuperAdmin(player) && playerdata.isFrozen()) { TFM_Util.setFlying(player, true); event.setTo(playerdata.getFreezeLocation()); } if (playerdata.isCaged()) { Location targetPos = player.getLocation().add(0, 1, 0); boolean outOfCage; if (!targetPos.getWorld().equals(playerdata.getCagePos().getWorld())) { outOfCage = true; } else { outOfCage = targetPos.distanceSquared(playerdata.getCagePos()) > (2.5 * 2.5); } if (outOfCage) { playerdata.setCaged( true, targetPos, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER), playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER)); playerdata.regenerateHistory(); playerdata.clearHistory(); TFM_Util.buildHistory(targetPos, 2, playerdata); TFM_Util.generateHollowCube( targetPos, 2, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.OUTER)); TFM_Util.generateCube( targetPos, 1, playerdata.getCageMaterial(TFM_PlayerData.CageLayer.INNER)); } } if (playerdata.isOrbiting()) { if (player.getVelocity().length() < playerdata.orbitStrength() * (2.0 / 3.0)) { player.setVelocity(new Vector(0, playerdata.orbitStrength(), 0)); } } if (TFM_Jumppads.getMode().isOn()) { TFM_Jumppads.PlayerMoveEvent(event); } if (!(TFM_ConfigEntry.LANDMINES_ENABLED.getBoolean() && TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean())) { return; } final Iterator<Command_landmine.TFM_LandmineData> landmines = Command_landmine.TFM_LandmineData.landmines.iterator(); while (landmines.hasNext()) { final Command_landmine.TFM_LandmineData landmine = landmines.next(); final Location location = landmine.location; if (location.getBlock().getType() != Material.TNT) { landmines.remove(); continue; } if (landmine.player.equals(player)) { break; } if (!player.getWorld().equals(location.getWorld())) { continue; } if (!(player.getLocation().distanceSquared(location) <= (landmine.radius * landmine.radius))) { break; } landmine.location.getBlock().setType(Material.AIR); final TNTPrimed tnt1 = location.getWorld().spawn(location, TNTPrimed.class); tnt1.setFuseTicks(40); tnt1.setPassenger(player); tnt1.setVelocity(new Vector(0.0, 2.0, 0.0)); final TNTPrimed tnt2 = location.getWorld().spawn(player.getLocation(), TNTPrimed.class); tnt2.setFuseTicks(1); player.setGameMode(GameMode.SURVIVAL); landmines.remove(); } }