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

@ -24,13 +24,11 @@ declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityArmorChangeEvent;
use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\InventoryContentPacket;
use pocketmine\network\mcpe\protocol\InventorySlotPacket;
use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket;
use pocketmine\Player;
use pocketmine\Server;
class ArmorInventory extends BaseInventory{
public const SLOT_HEAD = 0;
@ -90,15 +88,6 @@ class ArmorInventory extends BaseInventory{
return $this->setItem(self::SLOT_FEET, $boots);
}
protected function doSetItemEvents(int $index, Item $newItem) : ?Item{
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityArmorChangeEvent($this->getHolder(), $this->getItem($index), $newItem, $index));
if($ev->isCancelled()){
return null;
}
return $ev->getNewItem();
}
public function sendSlot(int $index, $target) : void{
if($target instanceof Player){
$target = [$target];