From 3409d332e7addbecec888787f29ef9b4b4b6f118 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 30 Aug 2014 17:57:30 +0200 Subject: [PATCH] Added survival check to movements --- src/pocketmine/Player.php | 47 +++++++++++++++++--------------- src/pocketmine/entity/Entity.php | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 437fd3220..5fd602a56 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1320,7 +1320,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $revert = false; if($newPos->distance($this) > 100){ - $this->server->getLogger()->warning($this->username." moved too quickly!"); + $this->server->getLogger()->warning($this->getName()." moved too quickly!"); $revert = true; }else{ @@ -1345,6 +1345,30 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } + if(!$revert){ + $dx = $newPos->x - $this->x; + $dy = $newPos->y - $this->y; + $dz = $newPos->z - $this->z; + + $this->setRotation($packet->yaw % 360, $packet->pitch % 360); + //$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); + $this->move($dx, $dy, $dz); + + $diffX = $this->x - $newPos->x; + $diffZ = $this->z - $newPos->z; + $diffY = $this->y - $newPos->y; + if($diffY > -0.5 or $diffY < 0.5){ + $diffY = 0; + } + + $diff = $diffX ** 2 + $diffY ** 2 + $diffZ ** 2; + + if($diff > 0.0625 and !$this->isSleeping() and ($this->gamemode & 0x01) === 0){ + $revert = true; + $this->server->getLogger()->warning($this->getName()." moved wrongly!"); + } + } + if($revert){ $pk = new MovePlayerPacket(); $pk->eid = 0; @@ -1356,27 +1380,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->yaw = $this->yaw; $pk->teleport = true; $this->directDataPacket($pk); - }else{ - $dx = $newPos->x - $this->x; - $dy = $newPos->y - $this->y; - $dz = $newPos->z - $this->z; - - $this->setRotation($packet->yaw % 360, $packet->pitch % 360); - //$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z); - $this->move($dx, $dy, $dz); - - if($this->x != $newPos->x or $this->y != $newPos->y or $this->z != $newPos->z){ - $pk = new MovePlayerPacket(); - $pk->eid = 0; - $pk->x = $this->x; - $pk->y = $this->y + 1.62; - $pk->z = $this->z; - $pk->bodyYaw = $this->yaw; - $pk->pitch = $this->pitch; - $pk->yaw = $this->yaw; - $pk->teleport = true; - $this->directDataPacket($pk); - } } break; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index a31365ef2..b6252a3e5 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -877,7 +877,7 @@ abstract class Entity extends Position implements Metadatable{ $this->boundingBox->offset(0, $dy, 0); } - if(($cx * $cx + $cz * $cz) >= ($dx * $dx + $dz * $dz)){ + if(($cx ** 2 + $cz ** 2) >= ($dx ** 2 + $dz ** 2)){ $dx = $cx; $dy = $cy; $dz = $cz;