Class ItemData

java.lang.Object
xyz.srnyx.javautilities.parents.Stringable
xyz.srnyx.annoyingapi.data.Data<org.bukkit.inventory.ItemStack>
xyz.srnyx.annoyingapi.data.ItemData
All Implemented Interfaces:
Annoyable

public class ItemData extends Data<org.bukkit.inventory.ItemStack>
Utility class for adding and getting data from item stacks
  • Constructor Details

    • ItemData

      public ItemData(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull org.bukkit.inventory.ItemStack item)
      Construct a new ItemData for the given item stack
      Parameters:
      plugin - Data.plugin
      item - Data.target
  • Method Details

    • attemptItemNbtApi

      @NotNull public @NotNull Optional<String> attemptItemNbtApi(@NotNull @NotNull Supplier<String> supplier)
      If the RuntimeLibrary.ITEM_NBT_API library isn't loaded, load it. Then attempt to run the given supplier and return the result
      Parameters:
      supplier - the supplier to attempt
      Returns:
      the result of the runnable
    • attemptItemNbtApi

      public void attemptItemNbtApi(@NotNull @NotNull Runnable runnable)
      If the RuntimeLibrary.ITEM_NBT_API library isn't loaded, load it. Then attempt to run the given runnable
      Parameters:
      runnable - the runnable to attempt
    • get

      @Nullable public @Nullable String get(@NotNull @NotNull String key)
      Get the data value for the given key
      Specified by:
      get in class Data<org.bukkit.inventory.ItemStack>
      Parameters:
      key - the key to get the data value for
      Returns:
      the data value, or null if not found
    • set

      protected boolean set(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Set the data value for the given key. If the key already exists, it will be overwritten
      Specified by:
      set in class Data<org.bukkit.inventory.ItemStack>
      Parameters:
      key - the key to set the data value for
      value - the data value to set
      Returns:
      true if the data value was set, false if it failed
    • remove

      public boolean remove(@NotNull @NotNull String key)
      Remove the data value with the given key
      Specified by:
      remove in class Data<org.bukkit.inventory.ItemStack>
      Parameters:
      key - the key to remove the data value for
      Returns:
      true if the data value was removed, false if it failed