Player: fixed crash when stopping using a chunk before it's finished being generated

This commit is contained in:
Dylan K. Taylor 2020-12-04 15:36:43 +00:00
parent 5ba09b6a25
commit e056456dd1

View File

@ -672,9 +672,12 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$world = $world ?? $this->getWorld(); $world = $world ?? $this->getWorld();
$index = World::chunkHash($x, $z); $index = World::chunkHash($x, $z);
if(isset($this->usedChunks[$index])){ if(isset($this->usedChunks[$index])){
foreach($world->getChunk($x, $z)->getEntities() as $entity){ $chunk = $world->getChunk($x, $z);
if($entity !== $this){ if($chunk !== null){ //this might be a chunk that hasn't been generated yet
$entity->despawnFrom($this); foreach($chunk->getEntities() as $entity){
if($entity !== $this){
$entity->despawnFrom($this);
}
} }
} }
$this->networkSession->stopUsingChunk($x, $z); $this->networkSession->stopUsingChunk($x, $z);