Player: Account for the possibility of Level being null in switchLevel()

the Entity base also accounts for this, and assuming that this is automatically valid is causing lots of crashes. I am not sure of the circumstances under which this is suddenly becoming null, but this shouldn't assume that the level is valid nonetheless.
This commit is contained in:
Dylan K. Taylor 2018-06-09 16:20:51 +01:00
parent 37b445f210
commit 601811f0f8

View File

@ -923,9 +923,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
protected function switchLevel(Level $targetLevel) : bool{
$oldLevel = $this->level;
if(parent::switchLevel($targetLevel)){
foreach($this->usedChunks as $index => $d){
Level::getXZ($index, $X, $Z);
$this->unloadChunk($X, $Z, $oldLevel);
if($oldLevel !== null){
foreach($this->usedChunks as $index => $d){
Level::getXZ($index, $X, $Z);
$this->unloadChunk($X, $Z, $oldLevel);
}
}
$this->usedChunks = [];