diff options
author | Erik Broes <erikbroes@ripe.net> | 2011-02-25 22:40:06 +0100 |
---|---|---|
committer | Erik Broes <erikbroes@ripe.net> | 2011-02-25 22:44:26 +0100 |
commit | 88dea6189a13a728e087c3b538de446a6b0291a3 (patch) | |
tree | 95910b5d6753234793ba9411ab204d7526c98fde /src/main/java | |
parent | 78af4f97f9a7125fcc914f52f83c93023359b281 (diff) | |
download | craftbukkit-88dea6189a13a728e087c3b538de446a6b0291a3.tar craftbukkit-88dea6189a13a728e087c3b538de446a6b0291a3.tar.gz craftbukkit-88dea6189a13a728e087c3b538de446a6b0291a3.tar.lz craftbukkit-88dea6189a13a728e087c3b538de446a6b0291a3.tar.xz craftbukkit-88dea6189a13a728e087c3b538de446a6b0291a3.zip |
Prevent movement event to be spammed for moving less than a pixel.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/net/minecraft/server/NetServerHandler.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index 4394cc38..ba372103 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -56,6 +56,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener { private int lastY; private int lastZ; + private double lastPosX = Double.MIN_VALUE; + private double lastPosY = Double.MIN_VALUE; + private double lastPosZ = Double.MIN_VALUE; + // Store the last block right clicked and what type it was private CraftBlock lastRightClicked; private BlockFace lastRightClickedFace; @@ -111,7 +115,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener { Player player = getPlayer(); Location from = new Location(player.getWorld(), i, j, k, this.e.yaw, this.e.pitch); Location to = player.getLocation(); - if (!from.equals(to)) { + + // Prevent 40 event-calls for less than a single pixel of movement >.> + double delta = Math.pow( this.lastPosX - this.i, 2) + Math.pow( this.lastPosY - this.j, 2) + Math.pow( this.lastPosZ - this.k, 2); + if (delta > 1f/256) { PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_MOVE, player, from, to); server.getPluginManager().callEvent(event); @@ -123,6 +130,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener { this.e.locZ = to.getZ(); this.e.yaw = to.getYaw(); this.e.pitch = to.getPitch(); + + this.lastPosX = this.e.locX; + this.lastPosY = this.e.locY; + this.lastPosZ = this.e.locZ; } // CraftBukkit end |