From a72488d41ec64d19f10e0c23180534ad452adba7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 29 Nov 2014 12:43:34 +0100 Subject: [PATCH] Updated player movement processing and event handling --- src/pocketmine/Player.php | 17 +++++++++++++++-- src/pocketmine/entity/Entity.php | 6 +++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4eed3bcae..91903b68f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1130,6 +1130,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $deltaAngle = abs($this->lastYaw - $to->yaw) + abs($this->lastPitch - $to->pitch); if(!$revert and ($delta > (1 / 16) or $deltaAngle > 10)){ + + $isFirst = ($this->lastX === null or $this->lastY === null or $this->lastZ === null); + $this->lastX = $to->x; $this->lastY = $to->y; $this->lastZ = $to->z; @@ -1137,9 +1140,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->lastYaw = $to->yaw; $this->lastPitch = $to->pitch; - $ev = new PlayerMoveEvent($this, $from, $to); + if(!$isFirst){ + $ev = new PlayerMoveEvent($this, $from, $to); - $this->server->getPluginManager()->callEvent($ev); + $this->server->getPluginManager()->callEvent($ev); + } if(!($revert = $ev->isCancelled())){ //Yes, this is intended if($to->distance($ev->getTo()) > 0.1){ //If plugins modify the destination @@ -1160,6 +1165,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } if($revert){ + + $this->lastX = $from->x; + $this->lastY = $from->y; + $this->lastZ = $from->z; + + $this->lastYaw = $from->yaw; + $this->lastPitch = $from->pitch; + $pk = new MovePlayerPacket(); $pk->eid = 0; $pk->x = $from->x; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 810f1c282..477d78f21 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -90,9 +90,9 @@ abstract class Entity extends Location implements Metadatable{ protected $lastDamageCause = null; - public $lastX; - public $lastY; - public $lastZ; + public $lastX = null; + public $lastY = null; + public $lastZ = null; public $motionX; public $motionY;