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); $this->allowFlight = (bool) ($this->gamemode & 0x01);
if(($level = $this->server->getLevelByName($nbt["Level"])) === null){ if(($level = $this->server->getLevelByName($nbt["Level"])) === null){
if($this->server->getDefaultLevel() instanceof Level){
$this->setLevel($this->server->getDefaultLevel()); $this->setLevel($this->server->getDefaultLevel());
$nbt["Level"] = $this->level->getName(); $nbt["Level"] = $this->level->getName();
$nbt["Pos"][0] = $this->level->getSpawnLocation()->x; $nbt["Pos"][0] = $this->level->getSpawnLocation()->x;
$nbt["Pos"][1] = $this->level->getSpawnLocation()->y; $nbt["Pos"][1] = $this->level->getSpawnLocation()->y;
$nbt["Pos"][2] = $this->level->getSpawnLocation()->z; $nbt["Pos"][2] = $this->level->getSpawnLocation()->z;
}else{
$this->close("", "No default level is loaded", true);
return;
}
}else{ }else{
$this->setLevel($level); $this->setLevel($level);
} }
@ -3081,7 +3086,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
* @param bool $notify * @param bool $notify
*/ */
public final function close($message = "", $reason = "generic reason", $notify = true){ public final function close($message = "", $reason = "generic reason", $notify = true){
if($this->connected and !$this->closed){ if($this->connected and !$this->closed){
if($notify and strlen((string) $reason) > 0){ if($notify and strlen((string) $reason) > 0){
$pk = new DisconnectPacket; $pk = new DisconnectPacket;
@ -3108,8 +3112,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
unset($this->usedChunks[$index]); unset($this->usedChunks[$index]);
} }
parent::close();
$this->interface->close($this, $notify ? $reason : ""); $this->interface->close($this, $notify ? $reason : "");
if($this->loggedIn){ if($this->loggedIn){
@ -3127,6 +3129,8 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
} }
parent::close();
$this->loggedIn = false; $this->loggedIn = false;
$this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); $this->server->getPluginManager()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this);
$this->spawned = false; $this->spawned = false;
@ -3142,7 +3146,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->loadQueue = []; $this->loadQueue = [];
$this->hasSpawned = []; $this->hasSpawned = [];
$this->spawnPosition = null; $this->spawnPosition = null;
}
if($this->perm !== null){ if($this->perm !== null){
$this->perm->clearPermissions(); $this->perm->clearPermissions();
@ -3158,6 +3161,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->server->removePlayer($this); $this->server->removePlayer($this);
} }
}
public function __debugInfo(){ public function __debugInfo(){
return []; return [];

View File

@ -1636,8 +1636,8 @@ abstract class Entity extends Location implements Metadatable{
if($this->chunk !== null){ if($this->chunk !== null){
$this->chunk->removeEntity($this); $this->chunk->removeEntity($this);
} }
if($this->level !== null){ if($this->getLevel() !== null){
$this->level->removeEntity($this); $this->getLevel()->removeEntity($this);
} }
} }
} }