From 403e996d2f92dc23d28444554ce9855138fc4e2b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 20 Mar 2018 10:49:23 +0000 Subject: [PATCH] Level: Removed WeakPosition This is a bad fix for an issue found in one specific use-case. This is redundant because the only places this is used are places where it's guaranteed to be valid, or places where it is checked to be valid anyway. The Level leak originally noted that led to the creation of this class is something I consider to be a non-issue, because all the heavy things will be cleaned up anyway. --- src/pocketmine/Player.php | 11 ++-- src/pocketmine/level/WeakPosition.php | 90 --------------------------- 2 files changed, 5 insertions(+), 96 deletions(-) delete mode 100644 src/pocketmine/level/WeakPosition.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 0b39ee2ed..77e869a52 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -86,7 +86,6 @@ use pocketmine\level\format\Chunk; use pocketmine\level\Level; use pocketmine\level\Location; use pocketmine\level\Position; -use pocketmine\level\WeakPosition; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\metadata\MetadataValue; @@ -299,7 +298,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var Vector3|null */ protected $sleeping = null; - /** @var WeakPosition|null */ + /** @var Position|null */ private $spawnPosition = null; //TODO: Abilities @@ -1166,7 +1165,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @return bool */ public function hasValidSpawnPosition() : bool{ - return $this->spawnPosition instanceof WeakPosition and $this->spawnPosition->isValid(); + return $this->spawnPosition !== null and $this->spawnPosition->isValid(); } /** @@ -1181,7 +1180,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ }else{ $level = $pos->getLevel(); } - $this->spawnPosition = new WeakPosition($pos->x, $pos->y, $pos->z, $level); + $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); $pk = new SetSpawnPositionPacket(); $pk->x = $this->spawnPosition->getFloorX(); $pk->y = $this->spawnPosition->getFloorY(); @@ -2099,9 +2098,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if(!$this->hasValidSpawnPosition()){ if(($level = $this->server->getLevelByName($this->namedtag->getString("SpawnLevel", ""))) instanceof Level){ - $this->spawnPosition = new WeakPosition($this->namedtag->getInt("SpawnX"), $this->namedtag->getInt("SpawnY"), $this->namedtag->getInt("SpawnZ"), $level); + $this->spawnPosition = new Position($this->namedtag->getInt("SpawnX"), $this->namedtag->getInt("SpawnY"), $this->namedtag->getInt("SpawnZ"), $level); }else{ - $this->spawnPosition = WeakPosition::fromObject($this->level->getSafeSpawn()); + $this->spawnPosition = $this->level->getSafeSpawn(); } } diff --git a/src/pocketmine/level/WeakPosition.php b/src/pocketmine/level/WeakPosition.php deleted file mode 100644 index b843970c7..000000000 --- a/src/pocketmine/level/WeakPosition.php +++ /dev/null @@ -1,90 +0,0 @@ -x = $x; - $this->y = $y; - $this->z = $z; - $this->levelId = ($level !== null ? $level->getId() : -1); - } - - public static function fromObject(Vector3 $pos, Level $level = null){ - return new WeakPosition($pos->x, $pos->y, $pos->z, $level); - } - - /** - * @return Level|null - */ - public function getLevel(){ - return Server::getInstance()->getLevel($this->levelId); - } - - /** - * @param Level|null $level - * - * @return $this - * - * @throws \InvalidArgumentException if the specified Level has been closed - */ - public function setLevel(Level $level = null){ - if($level !== null and $level->isClosed()){ - throw new \InvalidArgumentException("Specified level has been unloaded and cannot be used"); - } - - $this->levelId = ($level !== null ? $level->getId() : -1); - return $this; - } - - /** - * Returns a side Vector - * - * @param int $side - * @param int $step - * - * @return WeakPosition - */ - public function getSide(int $side, int $step = 1){ - assert($this->isValid()); - - return WeakPosition::fromObject(parent::getSide($side, $step), $this->level); - } - - public function __toString(){ - return "Weak" . parent::__toString(); - } -}