mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +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.
49 lines
1.6 KiB
PHP
49 lines
1.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\inventory;
|
|
|
|
use pocketmine\item\Item;
|
|
|
|
/**
|
|
* This interface can be used to listen for events on a specific Inventory.
|
|
*
|
|
* If you want to listen to changes on an inventory, create a class implementing this interface and implement its
|
|
* methods, then register it onto the inventory or inventories that you want to receive events for.
|
|
*/
|
|
interface InventoryEventProcessor{
|
|
|
|
/**
|
|
* Called prior to a slot in the given inventory changing. This is called by inventories that this listener is
|
|
* attached to.
|
|
*
|
|
* @param Inventory $inventory
|
|
* @param int $slot
|
|
* @param Item $oldItem
|
|
* @param Item $newItem
|
|
*
|
|
* @return Item|null that should be used in place of $newItem, or null if the slot change should not proceed.
|
|
*/
|
|
public function onSlotChange(Inventory $inventory, int $slot, Item $oldItem, Item $newItem) : ?Item;
|
|
}
|