From 03826d9cbc4446d8c290917cb77dc2db7408343c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 21 Jun 2017 12:17:26 +0100 Subject: [PATCH] Fixed player spawnpoints glitching and not saving --- src/pocketmine/Player.php | 16 ++++++++++------ .../command/defaults/SpawnpointCommand.php | 5 +++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4cf150693..24997893f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1849,8 +1849,12 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade protected function completeLoginSequence(){ parent::__construct($this->level, $this->namedtag); - if(!$this->hasValidSpawnPosition() and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName((string) $this->namedtag["SpawnLevel"])) instanceof Level){ - $this->spawnPosition = new WeakPosition($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level); + if(!$this->hasValidSpawnPosition()){ + if(isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName((string) $this->namedtag["SpawnLevel"])) instanceof Level){ + $this->spawnPosition = new WeakPosition($this->namedtag["SpawnX"], $this->namedtag["SpawnY"], $this->namedtag["SpawnZ"], $level); + }else{ + $this->spawnPosition = WeakPosition::fromObject($this->level->getSafeSpawn()); + } } $spawnPosition = $this->getSpawn(); @@ -3754,10 +3758,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } if($this->hasValidSpawnPosition()){ - $this->namedtag["SpawnLevel"] = $this->spawnPosition->getLevel()->getFolderName(); - $this->namedtag["SpawnX"] = (int) $this->spawnPosition->x; - $this->namedtag["SpawnY"] = (int) $this->spawnPosition->y; - $this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z; + $this->namedtag->SpawnLevel = new StringTag("SpawnLevel", $this->spawnPosition->getLevel()->getFolderName()); + $this->namedtag->SpawnX = new IntTag("SpawnX", (int) $this->spawnPosition->x); + $this->namedtag->SpawnY = new IntTag("SpawnY", (int) $this->spawnPosition->y); + $this->namedtag->SpawnZ = new IntTag("SpawnZ", (int) $this->spawnPosition->z); } foreach($this->achievements as $achievement => $status){ diff --git a/src/pocketmine/command/defaults/SpawnpointCommand.php b/src/pocketmine/command/defaults/SpawnpointCommand.php index 39ee16b77..05791f250 100644 --- a/src/pocketmine/command/defaults/SpawnpointCommand.php +++ b/src/pocketmine/command/defaults/SpawnpointCommand.php @@ -26,6 +26,7 @@ namespace pocketmine\command\defaults; use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\event\TranslationContainer; +use pocketmine\level\Level; use pocketmine\level\Position; use pocketmine\Player; use pocketmine\utils\TextFormat; @@ -70,8 +71,8 @@ class SpawnpointCommand extends VanillaCommand{ if(count($args) === 4){ if($level !== null){ $pos = $sender instanceof Player ? $sender->getPosition() : $level->getSpawnLocation(); - $x = (int) $this->getRelativeDouble($pos->x, $sender, $args[1]); - $y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, 128); + $x = $this->getRelativeDouble($pos->x, $sender, $args[1]); + $y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, Level::Y_MAX); $z = $this->getRelativeDouble($pos->z, $sender, $args[3]); $target->setSpawn(new Position($x, $y, $z, $level));