Player: call InventoryOpenEvent consistently

This commit is contained in:
Dylan K. Taylor 2019-06-14 19:31:33 +01:00
parent 2cb6fda286
commit 787d305c2a
3 changed files with 11 additions and 19 deletions

View File

@ -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;
}
/**

View File

@ -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{

View File

@ -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;