mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
* 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:
@ -30,6 +30,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\event\player\PlayerExhaustEvent;
|
||||
use pocketmine\event\player\PlayerExperienceChangeEvent;
|
||||
use pocketmine\inventory\EnderChestInventory;
|
||||
use pocketmine\inventory\EntityInventoryEventProcessor;
|
||||
use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\PlayerInventory;
|
||||
use pocketmine\item\Consumable;
|
||||
@ -570,6 +571,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
|
||||
$inventoryTag = $this->namedtag->getListTag("Inventory");
|
||||
if($inventoryTag !== null){
|
||||
$armorListener = $this->armorInventory->getEventProcessor();
|
||||
$this->armorInventory->setEventProcessor(null);
|
||||
|
||||
/** @var CompoundTag $item */
|
||||
foreach($inventoryTag as $i => $item){
|
||||
$slot = $item->getByte("Slot");
|
||||
@ -581,6 +585,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
$this->inventory->setItem($slot - 9, Item::nbtDeserialize($item));
|
||||
}
|
||||
}
|
||||
|
||||
$this->armorInventory->setEventProcessor($armorListener);
|
||||
}
|
||||
|
||||
$enderChestInventoryTag = $this->namedtag->getListTag("EnderChestInventory");
|
||||
@ -593,6 +599,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
|
||||
$this->inventory->setHeldItemIndex($this->namedtag->getInt("SelectedInventorySlot", 0), false);
|
||||
|
||||
$this->inventory->setEventProcessor(new EntityInventoryEventProcessor($this));
|
||||
|
||||
$this->setFood((float) $this->namedtag->getInt("foodLevel", (int) $this->getFood(), true));
|
||||
$this->setExhaustion($this->namedtag->getFloat("foodExhaustionLevel", $this->getExhaustion(), true));
|
||||
|
Reference in New Issue
Block a user