summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRigby <rigby@onarandombox.com>2011-07-26 21:30:34 +0100
committerEvilSeph <evilseph@gmail.com>2011-08-08 21:54:42 -0400
commit587b9662c98773812713e38100e2636668b99227 (patch)
tree52e49f89522b64a0d4518147c82ebed9f10b7168 /src
parent28b3c9b0d7ab7f3eba479483d5c24d54129e838f (diff)
downloadcraftbukkit-587b9662c98773812713e38100e2636668b99227.tar
craftbukkit-587b9662c98773812713e38100e2636668b99227.tar.gz
craftbukkit-587b9662c98773812713e38100e2636668b99227.tar.lz
craftbukkit-587b9662c98773812713e38100e2636668b99227.tar.xz
craftbukkit-587b9662c98773812713e38100e2636668b99227.zip
More PlayerMove fixes.
Revert the 'from' location changes. Only fire a PlayerMoveEvent if the movement is going to be processed. Attempt to catch Teleporting within the event better. Fixed issue where PlayerMove would not fire as often as expected. Thanks EvenPrime!
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/minecraft/server/NetServerHandler.java35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java
index 43b45647..6a454895 100644
--- a/src/main/java/net/minecraft/server/NetServerHandler.java
+++ b/src/main/java/net/minecraft/server/NetServerHandler.java
@@ -69,6 +69,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
private double lastPosZ = Double.MAX_VALUE;
private float lastPitch = Float.MAX_VALUE;
private float lastYaw = Float.MAX_VALUE;
+ private boolean justTeleported = false;
// For the packet15 hack :(
Long lastPacket;
@@ -138,7 +139,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
// CraftBukkit start
Player player = this.getPlayer();
- Location from = player.getLocation().clone(); // Get the Players current location.
+ Location from = new Location(player.getWorld(), lastPosX, lastPosY, lastPosZ, lastYaw, lastPitch); // Get the Players previous Event location.
Location to = player.getLocation().clone(); // Start off the To location as the Players current location.
// If the packet contains movement information then we update the To location with the correct XYZ.
@@ -155,12 +156,18 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
}
// Prevent 40 event-calls for less than a single pixel of movement >.>
- double delta = Math.pow(this.lastPosX - this.x, 2) + Math.pow(this.lastPosY - this.y, 2) + Math.pow(this.lastPosZ - this.z, 2);
- float deltaAngle = Math.abs(this.lastYaw - this.player.yaw) + Math.abs(this.lastPitch - this.player.pitch);
+ double delta = Math.pow(this.lastPosX - to.getX(), 2) + Math.pow(this.lastPosY - to.getY(), 2) + Math.pow(this.lastPosZ - to.getZ(), 2);
+ float deltaAngle = Math.abs(this.lastYaw - to.getYaw()) + Math.abs(this.lastPitch - to.getPitch());
+
+ if ((delta > 1f / 256 || deltaAngle > 10f) && (this.checkMovement && !this.player.dead)) {
+ this.lastPosX = to.getX();
+ this.lastPosY = to.getY();
+ this.lastPosZ = to.getZ();
+ this.lastYaw = to.getYaw();
+ this.lastPitch = to.getPitch();
- if (delta > 1f / 256 || deltaAngle > 10f) {
// Skip the first time we do this
- if (this.lastPosX != Double.MAX_VALUE) {
+ if (from.getX() != Double.MAX_VALUE) {
PlayerMoveEvent event = new PlayerMoveEvent(player, from, to);
this.server.getPluginManager().callEvent(event);
@@ -174,22 +181,17 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
there to avoid any 'Moved wrongly' or 'Moved too quickly' errors.
We only do this if the Event was not cancelled. */
if (!to.equals(event.getTo()) && !event.isCancelled()) {
- ((CraftPlayer) this.player.getBukkitEntity()).teleport(event.getTo());
+ this.player.getBukkitEntity().teleport(event.getTo());
return;
}
/* Check to see if the Players Location has some how changed during the call of the event.
This can happen due to a plugin teleporting the player instead of using .setTo() */
- if(!from.equals(this.getPlayer().getLocation())){
+ if (!from.equals(this.getPlayer().getLocation()) && this.justTeleported) {
+ this.justTeleported = false;
return;
}
}
-
- this.lastPosX = this.player.locX;
- this.lastPosY = this.player.locY;
- this.lastPosZ = this.player.locZ;
- this.lastYaw = this.player.yaw;
- this.lastPitch = this.player.pitch;
}
if (Double.isNaN(packet10flying.x) || Double.isNaN(packet10flying.y) || Double.isNaN(packet10flying.z) || Double.isNaN(packet10flying.stance)) {
@@ -398,6 +400,13 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
if (Float.isNaN(f1)) {
f1 = 0;
}
+
+ this.lastPosX = d0;
+ this.lastPosY = d1;
+ this.lastPosZ = d2;
+ this.lastYaw = f;
+ this.lastPitch = f1;
+ this.justTeleported = true;
// CraftBukkit end
this.checkMovement = false;