Solved Should i start using NBT or just keep it this way(custom name)

Discussion in 'Spigot Plugin Development' started by Stellrow, Feb 7, 2020.

  1. So as im working on my biggest project im trying to improve the code and features as much as i can

    Rn im using the "noob" way of doing custom stuff,place a colored name on a item and use it for checks.

    Question is should i start using NBT over this? Im also concerned i will lose version compatibility once i go into NBTs.

    If ur familiar please explain me the goods/bads of using them
  2. Do not use NBT instead use the spigot-api persistence api. getPersistentDataContainer

    Code (Text):

    ItemStack its = new ItemStack(Material.STONE);
    ItemMeta meta = its.getItemMeta();

    // write
    meta.getPersistentDataContainer().set(new NamespacedKey(javaPlugin, "your_special_key"), PersistentDataType.STRING, "Your Custom Value");

    String yourCustomValue = meta.getPersistentDataContainer().get(new NamespacedKey(javaPlugin, "your_special_key"), PersistentDataType.STRING);

    • Useful Useful x 2
    • Agree Agree x 1
  3. As of Spigot version idk, you can add custom NBT-Tags using the PersistentDataHolder API. This is a convenient way of doing all NBT-stuff while not loosing version-compatibility
    • Useful Useful x 1
  4. Hmm so its that simple? well thats a pleasent surprise,thanks