Simplify InventoryAction implementation

none of these action types are able to fail now.
This commit is contained in:
Dylan K. Taylor 2019-06-13 18:35:05 +01:00
parent 44be2179c4
commit da4c646d27
5 changed files with 7 additions and 70 deletions

View File

@ -321,11 +321,7 @@ class InventoryTransaction{
} }
foreach($this->actions as $action){ foreach($this->actions as $action){
if($action->execute($this->source)){ $action->execute($this->source);
$action->onExecuteSuccess($this->source);
}else{
$action->onExecuteFail($this->source);
}
} }
$this->hasExecuted = true; $this->hasExecuted = true;

View File

@ -68,18 +68,8 @@ class CreativeInventoryAction extends InventoryAction{
* No need to do anything extra here: this type just provides a place for items to disappear or appear from. * No need to do anything extra here: this type just provides a place for items to disappear or appear from.
* *
* @param Player $source * @param Player $source
*
* @return bool
*/ */
public function execute(Player $source) : bool{ public function execute(Player $source) : void{
return true;
}
public function onExecuteSuccess(Player $source) : void{
}
public function onExecuteFail(Player $source) : void{
} }
} }

View File

@ -55,19 +55,8 @@ class DropItemAction extends InventoryAction{
* Drops the target item in front of the player. * Drops the target item in front of the player.
* *
* @param Player $source * @param Player $source
*
* @return bool
*/ */
public function execute(Player $source) : bool{ public function execute(Player $source) : void{
$source->dropItem($this->targetItem); $source->dropItem($this->targetItem);
return true;
}
public function onExecuteSuccess(Player $source) : void{
}
public function onExecuteFail(Player $source) : void{
} }
} }

View File

@ -88,28 +88,10 @@ abstract class InventoryAction{
} }
/** /**
* Performs actions needed to complete the inventory-action server-side. Returns if it was successful. Will return * Performs actions needed to complete the inventory-action server-side. This will only be called if the transaction
* false if plugins cancelled events. This will only be called if the transaction which it is part of is considered * which it is part of is considered valid.
* 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 * @param Player $source
*/ */
abstract public function onExecuteSuccess(Player $source) : void; abstract public function execute(Player $source) : void;
/**
* Performs additional actions when this inventory-action did not complete successfully.
*
* @param Player $source
*/
abstract public function onExecuteFail(Player $source) : void;
} }

View File

@ -95,33 +95,13 @@ class SlotChangeAction extends InventoryAction{
* Sets the item into the target inventory. * Sets the item into the target inventory.
* *
* @param Player $source * @param Player $source
*
* @return bool
*/ */
public function execute(Player $source) : bool{ public function execute(Player $source) : void{
$this->inventory->setItem($this->inventorySlot, $this->targetItem, false); $this->inventory->setItem($this->inventorySlot, $this->targetItem, false);
return true;
}
/**
* Sends slot changes to other viewers of the inventory. This will not send any change back to the source Player.
*
* @param Player $source
*/
public function onExecuteSuccess(Player $source) : void{
foreach($this->inventory->getViewers() as $viewer){ foreach($this->inventory->getViewers() as $viewer){
if($viewer !== $source){ if($viewer !== $source){
$viewer->getNetworkSession()->syncInventorySlot($this->inventory, $this->inventorySlot); $viewer->getNetworkSession()->syncInventorySlot($this->inventory, $this->inventorySlot);
} }
} }
} }
/**
* Sends the original slot contents to the source player to revert the action.
*
* @param Player $source
*/
public function onExecuteFail(Player $source) : void{
$source->getNetworkSession()->syncInventorySlot($this->inventory, $this->inventorySlot);
}
} }