mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
InventoryTransaction::execute() now throws exceptions instead of returning true/false
This commit is contained in:
@ -269,12 +269,6 @@ class InventoryTransaction{
|
||||
}
|
||||
}
|
||||
|
||||
protected function sendInventories() : void{
|
||||
foreach($this->inventories as $inventory){
|
||||
$this->source->getNetworkSession()->getInvManager()->syncContents($inventory);
|
||||
}
|
||||
}
|
||||
|
||||
protected function callExecuteEvent() : bool{
|
||||
$ev = new InventoryTransactionEvent($this);
|
||||
$ev->call();
|
||||
@ -284,32 +278,24 @@ class InventoryTransaction{
|
||||
/**
|
||||
* Executes the group of actions, returning whether the transaction executed successfully or not.
|
||||
*
|
||||
* @throws TransactionValidationException
|
||||
* @throws TransactionException
|
||||
*/
|
||||
public function execute() : bool{
|
||||
public function execute() : void{
|
||||
if($this->hasExecuted()){
|
||||
$this->sendInventories();
|
||||
return false;
|
||||
throw new TransactionValidationException("Transaction has already been executed");
|
||||
}
|
||||
|
||||
$this->shuffleActions();
|
||||
|
||||
try{
|
||||
$this->validate();
|
||||
}catch(TransactionValidationException $e){
|
||||
$this->sendInventories();
|
||||
throw $e;
|
||||
}
|
||||
$this->validate();
|
||||
|
||||
if(!$this->callExecuteEvent()){
|
||||
$this->sendInventories();
|
||||
return false;
|
||||
throw new TransactionCancelledException("Transaction event cancelled");
|
||||
}
|
||||
|
||||
foreach($this->actions as $action){
|
||||
if(!$action->onPreExecute($this->source)){
|
||||
$this->sendInventories();
|
||||
return false;
|
||||
throw new TransactionCancelledException("One of the actions in this transaction was cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,8 +304,6 @@ class InventoryTransaction{
|
||||
}
|
||||
|
||||
$this->hasExecuted = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasExecuted() : bool{
|
||||
|
Reference in New Issue
Block a user