java.lang.Object
io.rhythmknights.coreapi.component.module.nbt.LegacyNBT
All Implemented Interfaces:
NBTWrapper

public final class LegacyNBT extends Object implements NBTWrapper
Class to set / get NBT tags from items.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.bukkit.inventory.ItemStack
    asBukkitCopy(Object nmsItemStack)
    Mimics the CraftItemStack#asBukkitCopy method.
    static Object
    asNMSCopy(org.bukkit.inventory.ItemStack itemStack)
    Mimics the CraftItemStack#asNMSCopy method.
    @Nullable String
    getString(@NotNull org.bukkit.inventory.ItemStack itemStack, String key)
    Gets the NBT tag based on a given key.
    static Object
    getTag(Object nmsItemStack)
    Mimics the nmsItemStack#getTag method.
    org.bukkit.inventory.ItemStack
    removeTag(@NotNull org.bukkit.inventory.ItemStack itemStack, String key)
    Removes a tag from an ItemStack.
    org.bukkit.inventory.ItemStack
    setBoolean(@NotNull org.bukkit.inventory.ItemStack itemStack, String key, boolean value)
    Sets a boolean to the ItemStack.
    org.bukkit.inventory.ItemStack
    setString(@NotNull org.bukkit.inventory.ItemStack itemStack, String key, String value)
    Sets an NBT tag to the an ItemStack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PACKAGE_NAME

      public static final String PACKAGE_NAME
    • NMS_VERSION

      public static final String NMS_VERSION
  • Constructor Details

    • LegacyNBT

      public LegacyNBT()
  • Method Details

    • setString

      public org.bukkit.inventory.ItemStack setString(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, String key, String value)
      Sets an NBT tag to the an ItemStack.
      Specified by:
      setString in interface NBTWrapper
      Parameters:
      itemStack - The current ItemStack to be set.
      key - The NBT key to use.
      value - The tag value to set.
      Returns:
      An ItemStack that has NBT set.
    • removeTag

      public org.bukkit.inventory.ItemStack removeTag(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, String key)
      Removes a tag from an ItemStack.
      Specified by:
      removeTag in interface NBTWrapper
      Parameters:
      itemStack - The current ItemStack to be remove.
      key - The NBT key to remove.
      Returns:
      An ItemStack that has the tag removed.
    • setBoolean

      public org.bukkit.inventory.ItemStack setBoolean(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, String key, boolean value)
      Sets a boolean to the ItemStack. Mainly used for setting an item to be unbreakable on older versions.
      Specified by:
      setBoolean in interface NBTWrapper
      Parameters:
      itemStack - The ItemStack to set the boolean to.
      key - The key to use.
      value - The boolean value.
      Returns:
      An ItemStack with a boolean value set.
    • getString

      @Nullable public @Nullable String getString(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack, String key)
      Gets the NBT tag based on a given key.
      Specified by:
      getString in interface NBTWrapper
      Parameters:
      itemStack - The ItemStack to get from.
      key - The key to look for.
      Returns:
      The tag that was stored in the ItemStack.
    • getTag

      public static Object getTag(Object nmsItemStack)
      Mimics the nmsItemStack#getTag method.
      Parameters:
      nmsItemStack - The NMS ItemStack to get from.
      Returns:
      The tag compound.
    • asNMSCopy

      public static Object asNMSCopy(org.bukkit.inventory.ItemStack itemStack)
      Mimics the CraftItemStack#asNMSCopy method.
      Parameters:
      itemStack - The ItemStack to make NMS copy.
      Returns:
      An NMS copy of the ItemStack.
    • asBukkitCopy

      public static org.bukkit.inventory.ItemStack asBukkitCopy(Object nmsItemStack)
      Mimics the CraftItemStack#asBukkitCopy method.
      Parameters:
      nmsItemStack - The NMS ItemStack to turn into ItemStack.
      Returns:
      The new ItemStack.