diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 85c4dc8fd..f2d20d329 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3100,6 +3100,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade foreach($this->usedChunks as $index => $d){ Level::getXZ($index, $chunkX, $chunkZ); $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); + foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ + $entity->despawnFrom($this, false); + } unset($this->usedChunks[$index]); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 91f9443aa..618452bc3 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -708,11 +708,13 @@ abstract class Entity extends Location implements Metadatable{ /** * @param Player $player */ - public function despawnFrom(Player $player){ + public function despawnFrom(Player $player, bool $send = true){ if(isset($this->hasSpawned[$player->getLoaderId()])){ - $pk = new RemoveEntityPacket(); - $pk->eid = $this->id; - $player->dataPacket($pk); + if($send){ + $pk = new RemoveEntityPacket(); + $pk->eid = $this->id; + $player->dataPacket($pk); + } unset($this->hasSpawned[$player->getLoaderId()]); } }