From 8f45d08ea33fb11949f07f317afa8ef236d27e13 Mon Sep 17 00:00:00 2001 From: Lemon Date: Sat, 21 Oct 2017 22:28:20 +0500 Subject: [PATCH] Fix movement exploit --- .../totalfreedommod/MovementValidator.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index 2b387dc8..5b9854b5 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -4,12 +4,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerLoginEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; public class MovementValidator extends FreedomService { - public static final int MAX_XZ_COORD = 30000000; + public static final int MAX_XYZ_COORD = 29999998; public MovementValidator(TotalFreedomMod plugin) { @@ -30,19 +31,32 @@ public class MovementValidator extends FreedomService public void onPlayerTeleport(PlayerTeleportEvent event) { // Check absolute value to account for negatives - if (Math.abs(event.getTo().getX()) >= MAX_XZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XZ_COORD) + if (Math.abs(event.getTo().getX()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getY()) >= MAX_XYZ_COORD) { event.setCancelled(true); // illegal position, cancel it } } + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerMove(PlayerMoveEvent event) + { + final Player player = event.getPlayer(); + + // Check absolute value to account for negatives + if (Math.abs(event.getTo().getX()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getY()) >= MAX_XYZ_COORD) + { + event.setCancelled(true); + player.teleport(player.getWorld().getSpawnLocation()); + } + } + @EventHandler(priority = EventPriority.HIGH) public void onPlayerLogin(PlayerLoginEvent event) { final Player player = event.getPlayer(); // Validate position - if (Math.abs(player.getLocation().getX()) >= MAX_XZ_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XZ_COORD) + if (Math.abs(player.getLocation().getX()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getY()) >= MAX_XYZ_COORD) { player.teleport(player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn }