don't spam listeners with slot-change notifications when doing a content change

This commit is contained in:
Dylan K. Taylor 2019-05-20 15:45:15 +01:00
parent c13b352b76
commit 04d0b6c054

View File

@ -108,6 +108,9 @@ abstract class BaseInventory implements Inventory{
$items = array_slice($items, 0, $this->getSize(), true);
}
$listeners = $this->listeners;
$this->listeners = [];
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
if(!isset($items[$i])){
if($this->slots[$i] !== null){
@ -120,6 +123,8 @@ abstract class BaseInventory implements Inventory{
}
}
$this->addChangeListeners(...$listeners); //don't directly write, in case listeners were added while operation was in progress
foreach($this->listeners as $listener){
$listener->onContentChange($this);
}