Implemented an InventoryEventProcessor, fixes #1986 (#2176)

* Implemented InventoryEventProcessor, fixes #1986
Event processors can now be registered and unregistered at will. Entity inventory/armor change events are now handled by event processors instead of the inventories themselves, which allows enabling/disabling the calling of these events at will.
This now avoids stupid things happening when initializing inventory contents, since the callers for those events are now registered _after_ the contents are initialized.
This commit is contained in:
Dylan K. Taylor
2018-06-09 17:37:10 +01:00
committed by GitHub
parent 8e5aca70b4
commit f6481eab8f
11 changed files with 159 additions and 43 deletions

View File

@ -31,6 +31,7 @@ use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\event\entity\EntityEffectAddEvent;
use pocketmine\event\entity\EntityEffectRemoveEvent;
use pocketmine\inventory\ArmorInventory;
use pocketmine\inventory\ArmorInventoryEventProcessor;
use pocketmine\item\Armor;
use pocketmine\item\Consumable;
use pocketmine\item\enchantment\Enchantment;
@ -76,6 +77,8 @@ abstract class Living extends Entity implements Damageable{
parent::initEntity();
$this->armorInventory = new ArmorInventory($this);
//TODO: load/save armor inventory contents
$this->armorInventory->setEventProcessor(new ArmorInventoryEventProcessor($this));
$health = $this->getMaxHealth();