mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 19:37:17 +00:00
ChunkCache: clean up handling of cache cleanup on world unload
This commit is contained in:
parent
e392a6a807
commit
88c6dcf46d
@ -51,6 +51,16 @@ class ChunkCache implements ChunkListener{
|
||||
public static function getInstance(World $world, Compressor $compressor) : self{
|
||||
$worldId = spl_object_id($world);
|
||||
$compressorId = spl_object_id($compressor);
|
||||
if(!isset(self::$instances[$worldId])){
|
||||
self::$instances[$worldId] = [];
|
||||
$world->addOnUnloadCallback(static function() use ($worldId) : void{
|
||||
foreach(self::$instances[$worldId] as $cache){
|
||||
$cache->caches = [];
|
||||
}
|
||||
unset(self::$instances[$worldId]);
|
||||
\GlobalLogger::get()->debug("Destroyed chunk packet caches for world#$worldId");
|
||||
});
|
||||
}
|
||||
if(!isset(self::$instances[$worldId][$compressorId])){
|
||||
\GlobalLogger::get()->debug("Created new chunk packet cache (world#$worldId, compressor#$compressorId)");
|
||||
self::$instances[$worldId][$compressorId] = new self($world, $compressor);
|
||||
@ -74,12 +84,6 @@ class ChunkCache implements ChunkListener{
|
||||
private function __construct(World $world, Compressor $compressor){
|
||||
$this->world = $world;
|
||||
$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");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user