From 04d0b6c0547daca6b97fa64d11f421a1ba2180a2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 20 May 2019 15:45:15 +0100 Subject: [PATCH] don't spam listeners with slot-change notifications when doing a content change --- src/pocketmine/inventory/BaseInventory.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 9be938cbf..a58001cb1 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -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); }