Level: add unregisterChunkListenerFromAll()

it's not expected for chunk listeners to have to track all the chunks they are listening to under normal circumstances.
This commit is contained in:
Dylan K. Taylor 2019-02-21 14:51:16 +00:00
parent f9da0f3ece
commit fd4a441f3a

View File

@ -713,6 +713,23 @@ class Level implements ChunkManager, Metadatable{
}
}
/**
* Unregisters a chunk listener from all chunks it is listening on in this Level.
*
* @param ChunkListener $listener
*/
public function unregisterChunkListenerFromAll(ChunkListener $listener) : void{
$id = spl_object_id($listener);
foreach($this->chunkListeners as $hash => $listeners){
if(isset($listeners[$id])){
unset($this->chunkListeners[$hash][$id]);
if(empty($this->chunkListeners[$hash])){
unset($this->chunkListeners[$hash]);
}
}
}
}
/**
* Returns all the listeners attached to this chunk.
*