From ce989876af79534f25648223d6ee3968917deb6f Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 31 Oct 2014 16:39:32 +0100 Subject: [PATCH] Improved freeing chunks --- src/pocketmine/Player.php | 8 +++++++- src/pocketmine/entity/Entity.php | 3 +-- src/pocketmine/level/Level.php | 12 ------------ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index d9d2819bbe..14ca35f3c5 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2329,7 +2329,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $this->interface->close($this, $reason); - $this->level->freeAllChunks($this); + + $chunkX = $chunkZ = null; + foreach($this->usedChunks as $index => $d){ + Level::getXZ($index, $chunkX, $chunkZ); + $this->level->freeChunk($chunkX, $chunkZ, $this); + } parent::close(); @@ -2346,6 +2351,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->windowIndex = []; $this->usedChunks = []; $this->loadQueue = []; + $this->hasSpawned = []; $this->spawnPosition = null; unset($this->buffer); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 645ec0c334..a7eed4fbb3 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -748,9 +748,8 @@ abstract class Entity extends Location implements Metadatable{ foreach($this->level->getChunkEntities($X, $Z) as $entity){ $entity->despawnFrom($this); } - + $this->level->freeChunk($X, $Z, $this); } - $this->level->freeAllChunks($this); } } $this->setLevel($targetLevel, $this instanceof Player ? true : false); //Hard reference diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 576266bad6..60c24d83f1 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -409,18 +409,6 @@ class Level implements ChunkManager, Metadatable{ $this->usedChunks[$index][$player->getID()] = $player; } - /** - * WARNING: Do not use this, it's only for internal use. - * Changes to this function won't be recorded on the version. - * - * @param Player $player - */ - public function freeAllChunks(Player $player){ - foreach($this->usedChunks as $i => $c){ - unset($this->usedChunks[$i][$player->getID()]); - } - } - /** * WARNING: Do not use this, it's only for internal use. * Changes to this function won't be recorded on the version.