CreativeInventory per Player (#5694)

This commit is contained in:
BrandPVP
2023-07-06 13:08:13 +03:00
committed by GitHub
parent 8f217ca6e0
commit c01d2dc718
4 changed files with 25 additions and 6 deletions

View File

@ -80,6 +80,7 @@ use pocketmine\event\player\PlayerViewDistanceChangeEvent;
use pocketmine\form\Form;
use pocketmine\form\FormValidationException;
use pocketmine\inventory\CallbackInventoryListener;
use pocketmine\inventory\CreativeInventory;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\PlayerCraftingInventory;
use pocketmine\inventory\PlayerCursorInventory;
@ -217,6 +218,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
protected array $permanentWindows = [];
protected PlayerCursorInventory $cursorInventory;
protected PlayerCraftingInventory $craftingGrid;
protected CreativeInventory $creativeInventory;
protected int $messageCounter = 2;
@ -307,6 +309,8 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->uuid = $this->playerInfo->getUuid();
$this->xuid = $this->playerInfo instanceof XboxLivePlayerInfo ? $this->playerInfo->getXuid() : "";
$this->creativeInventory = CreativeInventory::getInstance();
$rootPermissions = [DefaultPermissions::ROOT_USER => true];
if($this->server->isOp($this->username)){
$rootPermissions[DefaultPermissions::ROOT_OPERATOR] = true;
@ -2532,6 +2536,24 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
return $this->craftingGrid;
}
/**
* Returns the creative inventory shown to the player.
* Unless changed by a plugin, this is usually the same for all players.
*/
public function getCreativeInventory() : CreativeInventory{
return $this->creativeInventory;
}
/**
* To set a custom creative inventory, you need to make a clone of a CreativeInventory instance.
*/
public function setCreativeInventory(CreativeInventory $inventory) : void{
$this->creativeInventory = $inventory;
if($this->spawned && $this->isConnected()){
$this->getNetworkSession()->getInvManager()?->syncCreative();
}
}
/**
* @internal Called to clean up crafting grid and cursor inventory when it is detected that the player closed their
* inventory.