From 5e97da2e11270d87c950e3c35709b8bc10a00447 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 27 May 2014 01:56:25 +0200 Subject: [PATCH] Added InventoryTransactionEvent --- .../event/inventory/InventoryCloseEvent.php | 3 -- .../event/inventory/InventoryOpenEvent.php | 3 -- .../inventory/InventoryPickupItemEvent.php | 3 -- .../inventory/InventoryTransactionEvent.php | 50 +++++++++++++++++++ .../inventory/SimpleTransactionGroup.php | 8 +++ 5 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 src/pocketmine/event/inventory/InventoryTransactionEvent.php diff --git a/src/pocketmine/event/inventory/InventoryCloseEvent.php b/src/pocketmine/event/inventory/InventoryCloseEvent.php index 6cab54dcb..3ea0ae0ac 100644 --- a/src/pocketmine/event/inventory/InventoryCloseEvent.php +++ b/src/pocketmine/event/inventory/InventoryCloseEvent.php @@ -23,9 +23,6 @@ namespace pocketmine\event\inventory; use pocketmine\inventory\Inventory; use pocketmine\Player; -/** - * Called when a entity is despawned - */ class InventoryCloseEvent extends InventoryEvent{ public static $handlerList = null; diff --git a/src/pocketmine/event/inventory/InventoryOpenEvent.php b/src/pocketmine/event/inventory/InventoryOpenEvent.php index 1a1684e18..acda7b275 100644 --- a/src/pocketmine/event/inventory/InventoryOpenEvent.php +++ b/src/pocketmine/event/inventory/InventoryOpenEvent.php @@ -24,9 +24,6 @@ use pocketmine\event\Cancellable; use pocketmine\inventory\Inventory; use pocketmine\Player; -/** - * Called when a entity is despawned - */ class InventoryOpenEvent extends InventoryEvent implements Cancellable{ public static $handlerList = null; diff --git a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php index 98fb54825..1d86cf936 100644 --- a/src/pocketmine/event/inventory/InventoryPickupItemEvent.php +++ b/src/pocketmine/event/inventory/InventoryPickupItemEvent.php @@ -24,9 +24,6 @@ use pocketmine\event\Cancellable; use pocketmine\inventory\Inventory; use pocketmine\item\Item; -/** - * Called when a entity is despawned - */ class InventoryPickupItemEvent extends InventoryEvent implements Cancellable{ public static $handlerList = null; diff --git a/src/pocketmine/event/inventory/InventoryTransactionEvent.php b/src/pocketmine/event/inventory/InventoryTransactionEvent.php new file mode 100644 index 000000000..8227154e3 --- /dev/null +++ b/src/pocketmine/event/inventory/InventoryTransactionEvent.php @@ -0,0 +1,50 @@ +ts = $ts; + } + + public function getTransaction(){ + return $this->ts; + } + +} \ No newline at end of file diff --git a/src/pocketmine/inventory/SimpleTransactionGroup.php b/src/pocketmine/inventory/SimpleTransactionGroup.php index 390c42c35..8b6c3aad7 100644 --- a/src/pocketmine/inventory/SimpleTransactionGroup.php +++ b/src/pocketmine/inventory/SimpleTransactionGroup.php @@ -21,7 +21,9 @@ namespace pocketmine\inventory; +use pocketmine\event\inventory\InventoryTransactionEvent; use pocketmine\item\Item; +use pocketmine\Server; /** * This TransactionGroup only allows doing Transaction between one / two inventories @@ -96,6 +98,12 @@ class SimpleTransactionGroup implements TransactionGroup{ if($this->hasExecuted() or !$this->canExecute()){ return false; } + + Server::getInstance()->getPluginManager()->callEvent($ev = new InventoryTransactionEvent($this)); + if($ev->isCancelled()){ + return false; + } + foreach($this->transactions as $transaction){ $transaction->getInventory()->setItem($transaction->getSlot(), $transaction->getTargetItem()); }