ChunkCache: destroy cache when world is unloaded

This commit is contained in:
Dylan K. Taylor 2020-04-29 18:50:33 +01:00
parent 3ce9a4801f
commit b74f177958

View File

@ -74,6 +74,12 @@ class ChunkCache implements ChunkListener{
private function __construct(World $world, Compressor $compressor){ private function __construct(World $world, Compressor $compressor){
$this->world = $world; $this->world = $world;
$this->compressor = $compressor; $this->compressor = $compressor;
$worldId = spl_object_id($world);
$this->world->addOnUnloadCallback(function() use ($worldId) : void{
$this->caches = [];
unset(self::$instances[$worldId]);
\GlobalLogger::get()->debug("Destroyed chunk packet caches for world#$worldId");
});
} }
/** /**