Fixed crashes closing entities with unloaded levels

This commit is contained in:
Dylan K. Taylor 2017-02-15 17:51:41 +00:00
parent f8b9a13440
commit abffe1297d
2 changed files with 28 additions and 24 deletions

View File

@ -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(){

View File

@ -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);
}
}
}