diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index a81e1142b..188fd911f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1699,11 +1699,16 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->allowFlight = (bool) ($this->gamemode & 0x01); if(($level = $this->server->getLevelByName($nbt["Level"])) === null){ - $this->setLevel($this->server->getDefaultLevel()); - $nbt["Level"] = $this->level->getName(); - $nbt["Pos"][0] = $this->level->getSpawnLocation()->x; - $nbt["Pos"][1] = $this->level->getSpawnLocation()->y; - $nbt["Pos"][2] = $this->level->getSpawnLocation()->z; + if($this->server->getDefaultLevel() instanceof Level){ + $this->setLevel($this->server->getDefaultLevel()); + $nbt["Level"] = $this->level->getName(); + $nbt["Pos"][0] = $this->level->getSpawnLocation()->x; + $nbt["Pos"][1] = $this->level->getSpawnLocation()->y; + $nbt["Pos"][2] = $this->level->getSpawnLocation()->z; + }else{ + $this->close("", "No default level is loaded", true); + return; + } }else{ $this->setLevel($level); } @@ -3081,7 +3086,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade * @param bool $notify */ public final function close($message = "", $reason = "generic reason", $notify = true){ - if($this->connected and !$this->closed){ if($notify and strlen((string) $reason) > 0){ $pk = new DisconnectPacket; @@ -3108,8 +3112,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade unset($this->usedChunks[$index]); } - parent::close(); - $this->interface->close($this, $notify ? $reason : ""); if($this->loggedIn){ @@ -3127,6 +3129,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } } + parent::close(); + $this->loggedIn = false; $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->spawned = false; @@ -3142,21 +3146,21 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $this->loadQueue = []; $this->hasSpawned = []; $this->spawnPosition = null; + + if($this->perm !== null){ + $this->perm->clearPermissions(); + $this->perm = null; + } + + if($this->inventory !== null){ + $this->inventory = null; + $this->currentTransaction = null; + } + + $this->chunk = null; + + $this->server->removePlayer($this); } - - if($this->perm !== null){ - $this->perm->clearPermissions(); - $this->perm = null; - } - - if($this->inventory !== null){ - $this->inventory = null; - $this->currentTransaction = null; - } - - $this->chunk = null; - - $this->server->removePlayer($this); } public function __debugInfo(){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 1af830104..8f154b3df 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1636,8 +1636,8 @@ abstract class Entity extends Location implements Metadatable{ if($this->chunk !== null){ $this->chunk->removeEntity($this); } - if($this->level !== null){ - $this->level->removeEntity($this); + if($this->getLevel() !== null){ + $this->getLevel()->removeEntity($this); } } }