mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 00:29:54 +00:00
Player: call InventoryOpenEvent consistently
This commit is contained in:
parent
2cb6fda286
commit
787d305c2a
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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{
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user