From dfcff7eabf5937fa66b6115c866a3ad14a2cf9ce Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Fri, 20 Dec 2013 22:46:55 -0500 Subject: [PATCH] Account for different reach limit in Survival/Creative. Fixes BUKKIT-4257 When we first added the reach limiter in CraftBukkit there was no difference between how far the client could reach in vanilla while in Survival or Creative. At some point in Minecraft's cycle Creative was given a block extra to work with and our protection was not updated to account for this. We need to respect the possibility of different game modes in Minecraft providing the client with varying reach distances. --- .../java/net/minecraft/server/PlayerConnection.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java index e3bd043f84..29335eac52 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -55,6 +55,7 @@ import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.InventoryView; +import org.bukkit.util.NumberConversions; // CraftBukkit end public class PlayerConnection implements PacketPlayInListener { @@ -94,7 +95,8 @@ public class PlayerConnection implements PacketPlayInListener { private int lastTick = MinecraftServer.currentTick; private int lastDropTick = MinecraftServer.currentTick; private int dropCount = 0; - private static final int PLACE_DISTANCE_SQUARED = 6 * 6; + private static final int SURVIVAL_PLACE_DISTANCE_SQUARED = 6 * 6; + private static final int CREATIVE_PLACE_DISTANCE_SQUARED = 7 * 7; // Get position of last block hit for BlockDamageLevel.STOPPED private double lastPosX = Double.MAX_VALUE; @@ -618,7 +620,8 @@ public class PlayerConnection implements PacketPlayInListener { } else { // CraftBukkit start - Check if we can actually do something over this large a distance Location eyeLoc = this.getPlayer().getEyeLocation(); - if (Math.pow(eyeLoc.getX() - i, 2) + Math.pow(eyeLoc.getY() - j, 2) + Math.pow(eyeLoc.getZ() - k, 2) > PLACE_DISTANCE_SQUARED) { + double reachDistance = NumberConversions.square(eyeLoc.getX() - i) + NumberConversions.square(eyeLoc.getY() - j) + NumberConversions.square(eyeLoc.getZ() - k); + if (reachDistance > (this.getPlayer().getGameMode() == org.bukkit.GameMode.CREATIVE ? CREATIVE_PLACE_DISTANCE_SQUARED : SURVIVAL_PLACE_DISTANCE_SQUARED)) { return; } @@ -1606,8 +1609,7 @@ public class PlayerConnection implements PacketPlayInListener { this.server.getPluginManager().callEvent(event); if (!event.isCancelled()) { this.player.abilities.isFlying = packetplayinabilities.d(); // Actually set the player's flying status - } - else { + } else { this.player.updateAbilities(); // Tell the player their ability was reverted } }