Hi! Im currently working on a backpack plugin. For the backpack design i use the InvMenu Plugin developed by Muqsit(Thank you for that if you read it ) Here is the link: https://github.com/Muqsit/InvMenu Now i want to safe the Items which are set by the player with NBT Tags. I already started with: PHP: $menu->setInventoryCloseListener(function (Player $player, Inventory $inventory) { for ($slots = 0; $slots <= 40; $slots++) { $pName = $player->getName(); $item = $inventory->getItem($slots); $nbt = $item->getNamedTag() ?? new CompoundTag("", []); $nbt->inv = new StringTag($pName,"items"); $item->setNamedTag($nbt); } (I hope this is right) My Problem is now that when the player opens the Backpack the Items need to load(of course) but where can i "get" the Items from to even check if they have the right tag? Thanks for your help
Take a look at how MUQSIT himself did it. https://github.com/Muqsit/PlayerVaults/tree/master/src/muqsit/playervaults/database
Take a look at Item::jsonSerialize/Item::jsonDeserialize or Item::nbtSerialize/Item::nbtDeserialize depending on how you are saving the data
Alright i tried this: (This is where i save the items) PHP: $menu->setInventoryCloseListener(function (Player $player, Inventory $inventory) { for ($slots = 0; $slots <= 40; $slots++) { $pName = $player->getName(); $item = $inventory->getItem($slots); $value = $item->nbtSerialize(); $this->saveItemToConfig($value); } }); And this is where i try to give the Items PHP: for ($slots = 1; $slots <= 40; $slots++) { $items = $this->giveItemFromConfig($player); $cook = $items->nbtDeserialize(); $inv->setItem($slots,$items); } And these are the functions: PHP: public function saveItemToConfig(Item $item) { $cfg = new Config($this->getDataFolder().'config.sl', Config::SERIALIZED); $cfg->set('item', $item); $cfg->save(); } public function giveItemFromConfig(Player $player) { $cfg = new Config($this->getDataFolder().'config.sl', Config::SERIALIZED); $item = $cfg->get('item'); return $item; } And this is the failure: Code: [Server thread/CRITICAL]: Error: "Call to a member function nbtDeserialize() on bool" (EXCEPTION) in "plugins/Backpack/src/Tim/Backpack/Main" at line 100 I do not really unterstand the nbtDeserialize function. Someone could help me?
If you are saving into a config then I would suggest using Item::jsonSerialize/Item::jsonDeserialize If you want to save directly into player.dat, then take a look at https://github.com/alvin0319/Offhand/blob/master/src/alvin0319/Offhand/Offhand.php