mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-09 11:16:57 +00:00
Merge branch 'minor-next' into major-next
This commit is contained in:
@ -27,16 +27,24 @@ use pocketmine\crafting\CraftingManagerFromDataHelper;
|
||||
use pocketmine\crafting\json\ItemStackData;
|
||||
use pocketmine\data\bedrock\BedrockDataFiles;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\utils\DestructorCallbackTrait;
|
||||
use pocketmine\utils\Filesystem;
|
||||
use pocketmine\utils\ObjectSet;
|
||||
use pocketmine\utils\SingletonTrait;
|
||||
use pocketmine\utils\Utils;
|
||||
|
||||
final class CreativeInventory{
|
||||
use SingletonTrait;
|
||||
use DestructorCallbackTrait;
|
||||
|
||||
/** @var Item[] */
|
||||
private array $creative = [];
|
||||
|
||||
/** @phpstan-var ObjectSet<\Closure() : void> */
|
||||
private ObjectSet $contentChangedCallbacks;
|
||||
|
||||
private function __construct(){
|
||||
$this->contentChangedCallbacks = new ObjectSet();
|
||||
$creativeItems = CraftingManagerFromDataHelper::loadJsonArrayOfObjectsFile(
|
||||
BedrockDataFiles::CREATIVEITEMS_JSON,
|
||||
ItemStackData::class
|
||||
@ -57,6 +65,7 @@ final class CreativeInventory{
|
||||
*/
|
||||
public function clear() : void{
|
||||
$this->creative = [];
|
||||
$this->onContentChange();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,6 +95,7 @@ final class CreativeInventory{
|
||||
*/
|
||||
public function add(Item $item) : void{
|
||||
$this->creative[] = clone $item;
|
||||
$this->onContentChange();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,10 +106,22 @@ final class CreativeInventory{
|
||||
$index = $this->getItemIndex($item);
|
||||
if($index !== -1){
|
||||
unset($this->creative[$index]);
|
||||
$this->onContentChange();
|
||||
}
|
||||
}
|
||||
|
||||
public function contains(Item $item) : bool{
|
||||
return $this->getItemIndex($item) !== -1;
|
||||
}
|
||||
|
||||
/** @phpstan-return ObjectSet<\Closure() : void> */
|
||||
public function getContentChangedCallbacks() : ObjectSet{
|
||||
return $this->contentChangedCallbacks;
|
||||
}
|
||||
|
||||
private function onContentChange() : void{
|
||||
foreach($this->contentChangedCallbacks as $callback){
|
||||
$callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user