NBT-API

NBT-API

98.9k Downloads

Reading offline players

kangarko opened this issue ยท 3 comments

commented

Hi there,

Matej here, I am trying to replace PowerNBT with this plugin. My desired situation is I want to edit an offline player's inventory. I know there's NBTFile class however I have a few questions before continuing:

  1. To read the player nbt file is it safe to assume they are stored in the first world from Bukkit.getWorlds list?

  2. How does the saving mechanism work?

  3. How could I potentially get an ItemStack from NBTTag? See full code below, getItemFromNBT method.

This is my current code with PowerNBT imports removed:
snippet

Full code:
https://pastebin.com/9NEAEggJ

Thanks. A lot of people would benefit from this as I am using the code in the Confiscate plugin protecting against malicious items.

Matej

commented

Is now part of the nbt-data-api. (Not done, but simple working with player files is implemented)

commented

To read nbt files you can use "new NBTFile(file);", to get the file as a NBTCompound(or create it). For saving the NBTFile has a .save() method.
Now you can normally browse the nbt, and to get an ItemStack, there's the method "NBTItem.convertNBTtoItem(compound);" which will return a Bukkit ItemStack. For the inverse use "convertItemtoNBT".

commented

Thanks man awesome, will take a look at it soon!