mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 08:39:53 +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\EntityDamageByEntityEvent;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\inventory\InventoryCloseEvent;
|
use pocketmine\event\inventory\InventoryCloseEvent;
|
||||||
|
use pocketmine\event\inventory\InventoryOpenEvent;
|
||||||
use pocketmine\event\player\cheat\PlayerIllegalMoveEvent;
|
use pocketmine\event\player\cheat\PlayerIllegalMoveEvent;
|
||||||
use pocketmine\event\player\PlayerAchievementAwardedEvent;
|
use pocketmine\event\player\PlayerAchievementAwardedEvent;
|
||||||
use pocketmine\event\player\PlayerAnimationEvent;
|
use pocketmine\event\player\PlayerAnimationEvent;
|
||||||
@ -2814,16 +2815,17 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
$this->windowIndex[$networkId] = $inventory;
|
$this->windowIndex[$networkId] = $inventory;
|
||||||
$this->windows[spl_object_id($inventory)] = $networkId;
|
$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;
|
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;
|
namespace pocketmine\inventory;
|
||||||
|
|
||||||
use pocketmine\event\inventory\InventoryOpenEvent;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
@ -354,15 +353,8 @@ abstract class BaseInventory implements Inventory{
|
|||||||
$this->maxStackSize = $size;
|
$this->maxStackSize = $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function open(Player $who) : bool{
|
public function open(Player $who) : void{
|
||||||
$ev = new InventoryOpenEvent($this, $who);
|
|
||||||
$ev->call();
|
|
||||||
if($ev->isCancelled()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$this->onOpen($who);
|
$this->onOpen($who);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function close(Player $who) : void{
|
public function close(Player $who) : void{
|
||||||
|
@ -198,10 +198,8 @@ interface Inventory{
|
|||||||
* Tries to open the inventory to a player
|
* Tries to open the inventory to a player
|
||||||
*
|
*
|
||||||
* @param Player $who
|
* @param Player $who
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function open(Player $who) : bool;
|
public function open(Player $who) : void;
|
||||||
|
|
||||||
public function close(Player $who) : void;
|
public function close(Player $who) : void;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user