sourceItem = $sourceItem; $this->targetItem = $targetItem; } /** * Returns the item that was present before the action took place. * @return Item */ public function getSourceItem() : Item{ return clone $this->sourceItem; } /** * Returns the item that the action attempted to replace the source item with. * @return Item */ public function getTargetItem() : Item{ return clone $this->targetItem; } /** * Returns whether this action is currently valid. This should perform any necessary sanity checks. * * @param Player $source * * @return bool */ abstract public function isValid(Player $source) : bool; /** * Called when the action is added to the specified InventoryTransaction. * * @param InventoryTransaction $transaction */ public function onAddToTransaction(InventoryTransaction $transaction) : void{ } /** * Called by inventory transactions before any actions are processed. If this returns false, the transaction will * be cancelled. * * @param Player $source * * @return bool */ public function onPreExecute(Player $source) : bool{ return true; } /** * Performs actions needed to complete the inventory-action server-side. Returns if it was successful. Will return * false if plugins cancelled events. This will only be called if the transaction which it is part of is considered * valid. * * @param Player $source * * @return bool */ abstract public function execute(Player $source) : bool; /** * Performs additional actions when this inventory-action completed successfully. * * @param Player $source */ abstract public function onExecuteSuccess(Player $source) : void; /** * Performs additional actions when this inventory-action did not complete successfully. * * @param Player $source */ abstract public function onExecuteFail(Player $source) : void; }