Class ItemData

  • All Implemented Interfaces:
    Annoyable

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

    • Constructor Summary

      Constructors 
      Constructor Description
      ItemData​(@NotNull AnnoyingPlugin plugin, @NotNull org.bukkit.inventory.ItemStack item)
      Construct a new ItemData for the given item stack
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void attemptItemNbtApi​(@NotNull java.lang.Runnable runnable)
      If the RuntimeLibrary.ITEM_NBT_API library isn't loaded, load it.
      @NotNull java.util.Optional<java.lang.String> attemptItemNbtApi​(@NotNull java.util.function.Supplier<java.lang.String> supplier)
      If the RuntimeLibrary.ITEM_NBT_API library isn't loaded, load it.
      @Nullable java.lang.String get​(@NotNull java.lang.String key)
      Get the data value for the given key
      boolean remove​(@NotNull java.lang.String key)
      Remove the data value with the given key
      protected boolean set​(@NotNull java.lang.String key, @NotNull java.lang.String value)
      Set the data value for the given key.
      • Methods inherited from class xyz.srnyx.javautilities.parents.Stringable

        toString, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • 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 Detail

      • attemptItemNbtApi

        @NotNull
        public @NotNull java.util.Optional<java.lang.String> attemptItemNbtApi​(@NotNull
                                                                               @NotNull java.util.function.Supplier<java.lang.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 java.lang.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 java.lang.String get​(@NotNull
                                              @NotNull java.lang.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 java.lang.String key,
                              @NotNull
                              @NotNull java.lang.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 java.lang.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