diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index d8cff2eaf..2916cd428 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1479,7 +1479,7 @@ class Level implements ChunkManager, Metadatable{ } protected function queueUnloadChunk($x, $z){ - //TODO + $this->unloadQueue[Level::chunkHash($x, $z)] = microtime(true); } public function unloadChunkRequest($x, $z, $safe = true){ @@ -1501,7 +1501,7 @@ class Level implements ChunkManager, Metadatable{ return false; } - $this->provider->unloadChunk($x, $z); + $this->provider->unloadChunk($x, $z, $safe); Cache::remove("world:" . $this->getID() . ":$x:$z"); return true; @@ -1672,7 +1672,6 @@ class Level implements ChunkManager, Metadatable{ $Z = null; foreach($this->usedChunks as $i => $c){ if(count($c) === 0){ - unset($this->usedChunks[$i]); Level::getXZ($i, $X, $Z); if(!$this->isSpawnChunk($X, $Z)){ $this->unloadChunkRequest($X, $Z, true); @@ -1681,13 +1680,14 @@ class Level implements ChunkManager, Metadatable{ } if(count($this->unloadQueue) > 0){ - foreach($this->unloadQueue as $index => $chunk){ + foreach($this->unloadQueue as $index => $time){ + Level::getXZ($index, $X, $Z); - if($this->autoSave){ - $this->provider->saveChunk($chunk->getX(), $chunk->getZ()); + if($this->getAutoSave()){ + $this->provider->saveChunk($X, $Z); } //If the chunk can't be unloaded, it stays on the queue - if($this->unloadChunk($chunk->getX(), $chunk->getZ(), $this->getAutoSave())){ + if($this->unloadChunk($X, $Z, true)){ unset($this->unloadQueue[$index]); } }