mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-20 20:48:06 +00:00
Simplify InventoryAction implementation
none of these action types are able to fail now.
This commit is contained in:
parent
44be2179c4
commit
da4c646d27
@ -321,11 +321,7 @@ class InventoryTransaction{
|
||||
}
|
||||
|
||||
foreach($this->actions as $action){
|
||||
if($action->execute($this->source)){
|
||||
$action->onExecuteSuccess($this->source);
|
||||
}else{
|
||||
$action->onExecuteFail($this->source);
|
||||
}
|
||||
$action->execute($this->source);
|
||||
}
|
||||
|
||||
$this->hasExecuted = true;
|
||||
|
@ -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.
|
||||
*
|
||||
* @param Player $source
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(Player $source) : bool{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onExecuteSuccess(Player $source) : void{
|
||||
|
||||
}
|
||||
|
||||
public function onExecuteFail(Player $source) : void{
|
||||
public function execute(Player $source) : void{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -55,19 +55,8 @@ class DropItemAction extends InventoryAction{
|
||||
* Drops the target item in front of the player.
|
||||
*
|
||||
* @param Player $source
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function execute(Player $source) : bool{
|
||||
public function execute(Player $source) : void{
|
||||
$source->dropItem($this->targetItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onExecuteSuccess(Player $source) : void{
|
||||
|
||||
}
|
||||
|
||||
public function onExecuteFail(Player $source) : void{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -88,28 +88,10 @@ abstract class InventoryAction{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Performs actions needed to complete the inventory-action server-side. This will only be called if the transaction
|
||||
* which it is part of is considered valid.
|
||||
*
|
||||
* @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;
|
||||
|
||||
abstract public function execute(Player $source) : void;
|
||||
}
|
||||
|
@ -95,33 +95,13 @@ class SlotChangeAction extends InventoryAction{
|
||||
* Sets the item into the target inventory.
|
||||
*
|
||||
* @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);
|
||||
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){
|
||||
if($viewer !== $source){
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user