Interface NBTCompatibility

All Known Implementing Classes:
NBT_Persistent

public interface NBTCompatibility
This interface outlines a version dependant api that return values based on different ItemStack and tag input. There should be an implementing class for each minecraft protocol version.

NBT stands for Named Binary Tag.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int[]
     
    static final String[]
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default int[]
    getArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns the int[] value of a NBT tag with the given name key.
    int[]
    getArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int[] def)
    Returns the int[] value of a NBT tag with the given name key.
    default double
    getDouble(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns the Double value of a NBT tag with the given name key.
    double
    getDouble(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, double def)
    Returns the Double value of a NBT tag with the given name key.
    default int
    getInt(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns the Integer value of a NBT tag with the given name key.
    int
    getInt(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int def)
    Returns the Integer value of a NBT tag with the given name key.
    default org.bukkit.NamespacedKey
    getKey(String plugin, String key)
     
    @NotNull String
    getNBTDebug(@NotNull org.bukkit.inventory.ItemStack bukkitStack)
    Returns the Object.toString() value of an item's NBT compound, useful for debugging.
    default String
    getString(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns the String value of a NBT tag with the given name key.
    getString(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String def)
    Returns the String value of a NBT tag with the given name key.
    default String[]
    getStringArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns the String[] value of a NBT tag with the given name key.
    getStringArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String[] def)
    Returns the String[] value of a NBT tag with the given name key.
    boolean
    hasArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns true if the given bukkitItem's NBT compound has the given key, and it is an int[] value.
    boolean
    hasDouble(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns true if the given bukkitItem's NBT compound has the given key, and it is a Double value.
    boolean
    hasInt(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns true if the given bukkitItem's NBT compound has the given key, and it is an Integer value.
    boolean
    hasString(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns true if the given bukkitItem's NBT compound has the given key, and it is a String value.
    boolean
    hasStringArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Returns true if the given bukkitItem's NBT compound has the given key, and it is a String[] value.
    void
    remove(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key)
    Removes the given NBT tag from the item.
    void
    setArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int[] value)
    Sets the int[] value of a NBT tag with the given name key.
    void
    setDouble(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, double value)
    Sets the Double value of a NBT tag with the given name key.
    void
    setInt(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, int value)
    Sets the Integer value of a NBT tag with the given name key.
    void
    setString(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String value)
    Sets the String value of a NBT tag with the given name key.
    void
    setStringArray(@NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull String plugin, @NotNull String key, String[] value)
    Sets the Double value of a NBT tag with the given name key.
  • Field Details

    • DO_NOT_MODIFY_ME

      static final int[] DO_NOT_MODIFY_ME
    • DO_NOT_MODIFY_ME_STRING

      static final String[] DO_NOT_MODIFY_ME_STRING
  • Method Details

    • hasString

      boolean hasString(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns true if the given bukkitItem's NBT compound has the given key, and it is a String value. Otherwise, this method will return null.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to check existence of.
      Returns:
      true if the NBT compound uses the tag.
    • getString

      default String getString(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns the String value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return null.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      Returns:
      The value of the tag, or null.
    • getString

      String getString(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, String def)
      Returns the String value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return def.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      def - The default value to return if the key is not present.
      Returns:
      The value of the tag, or null.
    • setString

      void setString(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, String value)
      Sets the String value of a NBT tag with the given name key. The value is put in the NBT compound stored in the given item bukkitItem.

      The stored value can be seen using getString(ItemStack, String, String).

      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to store the value at.
      value - The value that will be stored.
    • hasInt

      boolean hasInt(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns true if the given bukkitItem's NBT compound has the given key, and it is an Integer value. Otherwise, this method will return null.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to check existence of.
      Returns:
      true if the NBT compound uses the tag.
    • getInt

      default int getInt(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns the Integer value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return 0.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      Returns:
      The value of the tag, or 0.
    • getInt

      int getInt(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, int def)
      Returns the Integer value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return def.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      def - The default value to return if the key is not present.
      Returns:
      The value of the tag, or 0.
    • setInt

      void setInt(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, int value)
      Sets the Integer value of a NBT tag with the given name key. The value is put in the NBT compound stored in the given item bukkitItem.

      The stored value can be seen using getInt(ItemStack, String, String).

      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to store the value at.
      value - The value that will be stored.
    • hasDouble

      boolean hasDouble(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns true if the given bukkitItem's NBT compound has the given key, and it is a Double value. Otherwise, this method will return null.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to check existence of.
      Returns:
      true if the NBT compound uses the tag.
    • getDouble

      default double getDouble(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns the Double value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return 0.0.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      Returns:
      The value of the tag, or 0.
    • getDouble

      double getDouble(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, double def)
      Returns the Double value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return def.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      def - The default value to return if the key is not present.
      Returns:
      The value of the tag, or 0.
    • setDouble

      void setDouble(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, double value)
      Sets the Double value of a NBT tag with the given name key. The value is put in a compound according to the given plugin, inside of the bukkitItem NBT compound.

      The stored value can be seen using getDouble(ItemStack, String, String).

      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to store the value at.
      value - The value that will be stored.
    • hasArray

      boolean hasArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns true if the given bukkitItem's NBT compound has the given key, and it is an int[] value. Otherwise, this method will return null.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to check existence of.
      Returns:
      true if the NBT compound uses the tag.
    • getArray

      default int[] getArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns the int[] value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return 0.0.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      Returns:
      The value of the tag, or an empty array.
    • getArray

      int[] getArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, int[] def)
      Returns the int[] value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return def.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      def - The default value to return if the key is not present.
      Returns:
      The value of the tag, or def.
    • setArray

      void setArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, int[] value)
      Sets the int[] value of a NBT tag with the given name key. The value is put in a compound according to the given plugin, inside of the bukkitItem NBT compound.

      The stored value can be seen using getArray(ItemStack, String, String).

      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to store the value at.
      value - The value that will be stored.
    • hasStringArray

      boolean hasStringArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns true if the given bukkitItem's NBT compound has the given key, and it is a String[] value. Otherwise, this method will return null.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to check existence of.
      Returns:
      true if the NBT compound uses the tag.
    • getStringArray

      default String[] getStringArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Returns the String[] value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return 0.0.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      Returns:
      The value of the tag, or an empty array.
    • getStringArray

      String[] getStringArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, String[] def)
      Returns the String[] value of a NBT tag with the given name key. The value is pulled from an NBT compound contained in the given item bukkitItem. If the tag isn't used in the item's compound, then this method will return def.
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to pull some value from.
      def - The default value to return if the key is not present.
      Returns:
      The value of the tag, or def.
    • setStringArray

      void setStringArray(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key, String[] value)
      Sets the Double value of a NBT tag with the given name key. The value is put in a compound according to the given plugin, inside of the bukkitItem NBT compound.

      The stored value can be seen using getStringArray(ItemStack, String, String).

      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to store the value at.
      value - The value that will be stored.
    • remove

      void remove(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitItem, @NotNull @NotNull String plugin, @NotNull @NotNull String key)
      Removes the given NBT tag from the item. To check to see if there was a key to delete, use hasString(ItemStack, String, String) (or one of the hasX methods).
      Parameters:
      bukkitItem - The non-null item that has an NBT tag compound.
      plugin - The non-null owner of the tag, should be your plugin.
      key - The non-null name of the tag to remove.
    • getKey

      default org.bukkit.NamespacedKey getKey(String plugin, String key)
    • getNBTDebug

      @NotNull @NotNull String getNBTDebug(@NotNull @NotNull org.bukkit.inventory.ItemStack bukkitStack)
      Returns the Object.toString() value of an item's NBT compound, useful for debugging.
      Parameters:
      bukkitStack - The non-null bukkit item to check the nbt tags of.
      Returns:
      The non-null string value of the nbt compound.