Code Examples
Code Examples
Using Maps
When using an NBT method that uses Maps, the following rules apply:
- When converting something into a Map, you'll always get a Map<String, Tag> where the Tag may contain any NBT type except for BOOL (because they don't exist in NBT data).
- When having a Map as parameter, the keys must be Strings and the values may be one of the following: byte[], int[], Boolean, Byte, Short, Integer, Long, Float, Double, String, List, Map, Tag
Basic
Let's say your plugin has to store items (org.bukkit.inventory.ItemStack) along other data in the same file (let's say YAML). All you have to do is:
String saved = NBT.saveItemStack64(itemStack);
and append it somewhere in the yaml configuration instance.
If you want to save a Map (e.g. a HashMap containing data about your plugin) you can do it like this:
String saved = NBT.saveNBT64(NBT.mapToNBT("root", yourHashMap));
Advanced
For one of my plugins (iSpawner) I need to save and load mob spawners to and from NBT, but if I included the Minecraft package (like I did before), I'd have to update my plugin with every new version.
Now, with NBTLib, I can do this: [ Click for paste ]