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.
This commit is contained in:
EvilSeph 2013-12-20 22:46:55 -05:00
parent 6d9a6fbb4b
commit dfcff7eabf

View File

@ -55,6 +55,7 @@ import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.util.NumberConversions;
// CraftBukkit end // CraftBukkit end
public class PlayerConnection implements PacketPlayInListener { public class PlayerConnection implements PacketPlayInListener {
@ -94,7 +95,8 @@ public class PlayerConnection implements PacketPlayInListener {
private int lastTick = MinecraftServer.currentTick; private int lastTick = MinecraftServer.currentTick;
private int lastDropTick = MinecraftServer.currentTick; private int lastDropTick = MinecraftServer.currentTick;
private int dropCount = 0; 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 // Get position of last block hit for BlockDamageLevel.STOPPED
private double lastPosX = Double.MAX_VALUE; private double lastPosX = Double.MAX_VALUE;
@ -618,7 +620,8 @@ public class PlayerConnection implements PacketPlayInListener {
} else { } else {
// CraftBukkit start - Check if we can actually do something over this large a distance // CraftBukkit start - Check if we can actually do something over this large a distance
Location eyeLoc = this.getPlayer().getEyeLocation(); 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; return;
} }
@ -1606,8 +1609,7 @@ public class PlayerConnection implements PacketPlayInListener {
this.server.getPluginManager().callEvent(event); this.server.getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
this.player.abilities.isFlying = packetplayinabilities.d(); // Actually set the player's flying status 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 this.player.updateAbilities(); // Tell the player their ability was reverted
} }
} }