From 7f838a8c3655ac2862be3a7a20f425f56ab9fec2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 31 Mar 2017 13:45:28 +0100 Subject: [PATCH] Fixed crashes due to adding players 'online' far too early, fixed some Player save logic --- src/pocketmine/Player.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index a67d3872c..1de47f2f7 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1797,7 +1797,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->sendPlayStatus(PlayStatusPacket::LOGIN_SUCCESS); $this->loggedIn = true; - $this->server->addOnlinePlayer($this); $pk = new ResourcePacksInfoPacket(); $manager = $this->server->getResourceManager(); @@ -1876,6 +1875,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->forceMovement = $this->teleportPosition = $this->getPosition(); + $this->server->addOnlinePlayer($this); + $this->server->onPlayerLogin($this); } @@ -3637,14 +3638,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } parent::saveNBT(); - if($this->getLevel() instanceof Level){ + + if($this->isValid()){ $this->namedtag->Level = new StringTag("Level", $this->level->getFolderName()); - 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; - } + } + + 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; } foreach($this->achievements as $achievement => $status){