From e056456dd121856cc2db2e3d8bc9a6dbcbd99662 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 4 Dec 2020 15:36:43 +0000 Subject: [PATCH] Player: fixed crash when stopping using a chunk before it's finished being generated --- src/player/Player.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/player/Player.php b/src/player/Player.php index c80c0b2b4..e5e2031bc 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -672,9 +672,12 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $world = $world ?? $this->getWorld(); $index = World::chunkHash($x, $z); if(isset($this->usedChunks[$index])){ - foreach($world->getChunk($x, $z)->getEntities() as $entity){ - if($entity !== $this){ - $entity->despawnFrom($this); + $chunk = $world->getChunk($x, $z); + if($chunk !== null){ //this might be a chunk that hasn't been generated yet + foreach($chunk->getEntities() as $entity){ + if($entity !== $this){ + $entity->despawnFrom($this); + } } } $this->networkSession->stopUsingChunk($x, $z);