mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +00:00
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:
parent
37b445f210
commit
601811f0f8
@ -923,10 +923,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
protected function switchLevel(Level $targetLevel) : bool{
|
protected function switchLevel(Level $targetLevel) : bool{
|
||||||
$oldLevel = $this->level;
|
$oldLevel = $this->level;
|
||||||
if(parent::switchLevel($targetLevel)){
|
if(parent::switchLevel($targetLevel)){
|
||||||
|
if($oldLevel !== null){
|
||||||
foreach($this->usedChunks as $index => $d){
|
foreach($this->usedChunks as $index => $d){
|
||||||
Level::getXZ($index, $X, $Z);
|
Level::getXZ($index, $X, $Z);
|
||||||
$this->unloadChunk($X, $Z, $oldLevel);
|
$this->unloadChunk($X, $Z, $oldLevel);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->usedChunks = [];
|
$this->usedChunks = [];
|
||||||
$this->level->sendTime($this);
|
$this->level->sendTime($this);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user