Updated player movement processing and event handling

This commit is contained in:
Shoghi Cervantes 2014-11-29 12:43:34 +01:00
parent 3930f379cf
commit a72488d41e
2 changed files with 18 additions and 5 deletions

View File

@ -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;

View File

@ -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;