diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 5a89d4a7d..8ccacf6e9 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -39,6 +39,7 @@ use pocketmine\entity\Skin; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\inventory\InventoryCloseEvent; +use pocketmine\event\inventory\InventoryOpenEvent; use pocketmine\event\player\cheat\PlayerIllegalMoveEvent; use pocketmine\event\player\PlayerAchievementAwardedEvent; use pocketmine\event\player\PlayerAnimationEvent; @@ -2814,16 +2815,17 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->windowIndex[$networkId] = $inventory; $this->windows[spl_object_id($inventory)] = $networkId; - if($inventory->open($this)){ - if($isPermanent){ - $this->permanentWindows[spl_object_id($inventory)] = true; - } - return $networkId; - }else{ - $this->removeWindow($inventory); + $ev = new InventoryOpenEvent($inventory, $this); + $ev->call(); + if($ev->isCancelled()){ return -1; } + $inventory->open($this); + if($isPermanent){ + $this->permanentWindows[spl_object_id($inventory)] = true; + } + return $networkId; } /** diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 204361799..63b19c6a6 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace pocketmine\inventory; -use pocketmine\event\inventory\InventoryOpenEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\Player; @@ -354,15 +353,8 @@ abstract class BaseInventory implements Inventory{ $this->maxStackSize = $size; } - public function open(Player $who) : bool{ - $ev = new InventoryOpenEvent($this, $who); - $ev->call(); - if($ev->isCancelled()){ - return false; - } + public function open(Player $who) : void{ $this->onOpen($who); - - return true; } public function close(Player $who) : void{ diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index d393a3e25..f23a41815 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -198,10 +198,8 @@ interface Inventory{ * Tries to open the inventory to a player * * @param Player $who - * - * @return bool */ - public function open(Player $who) : bool; + public function open(Player $who) : void; public function close(Player $who) : void;