InventoryAction: replace isValid() with validate() which throws TransactionValidationException

This commit is contained in:
Dylan K. Taylor
2020-07-04 19:38:34 +01:00
parent cf5e31c619
commit 1d18662d9b
6 changed files with 36 additions and 14 deletions

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\inventory\transaction\action;
use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\inventory\transaction\TransactionValidationException;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\player\Player;
@ -37,8 +38,10 @@ class DropItemAction extends InventoryAction{
parent::__construct(ItemFactory::air(), $targetItem);
}
public function isValid(Player $source) : bool{
return !$this->targetItem->isNull();
public function validate(Player $source) : void{
if($this->targetItem->isNull()){
throw new TransactionValidationException("Cannot drop an empty itemstack");
}
}
public function onPreExecute(Player $source) : bool{