Class CustomItemDataService

java.lang.Object
io.github.thebusybiscuit.slimefun4.core.services.CustomItemDataService
All Implemented Interfaces:
Keyed

public class CustomItemDataService extends Object implements Keyed
This Service is responsible for applying NBT data to a SlimefunItemStack. This is used to ensure that the id of a SlimefunItem is stored alongside any ItemStack at all times.
Author:
TheBusyBiscuit
See Also:
  • Constructor Details

    • CustomItemDataService

      public CustomItemDataService(@Nonnull Plugin plugin, @Nonnull String key)
      This creates a new CustomItemDataService for the given Plugin and the provided data key.
      Parameters:
      plugin - The Plugin for this service to use
      key - The key under which to store data
  • Method Details

    • getKey

      public NamespacedKey getKey()
      Specified by:
      getKey in interface Keyed
    • setItemData

      public void setItemData(@Nonnull ItemStack item, @Nonnull String id)
      This method stores the given id on the provided ItemStack via persistent data.
      Parameters:
      item - The ItemStack to store data on
      id - The id to store on the ItemStack
    • setItemData

      public void setItemData(@Nonnull ItemMeta meta, @Nonnull String id)
      This method stores the given id on the provided ItemMeta via persistent data.
      Parameters:
      meta - The ItemMeta to store data on
      id - The id to store on the ItemMeta
    • getItemData

      @Nonnull public Optional<String> getItemData(@Nullable ItemStack item)
      This method returns an Optional holding the data stored on the given ItemStack. The Optional will be empty if the given ItemStack is null, doesn't have any ItemMeta or if the requested data simply does not exist on that ItemStack.
      Parameters:
      item - The ItemStack to check
      Returns:
      An Optional describing the result
    • getItemData

      @Nonnull public Optional<String> getItemData(@Nonnull ItemMeta meta)
      This method returns an Optional, either empty or holding the data stored on the given ItemMeta.
      Parameters:
      meta - The ItemMeta to check
      Returns:
      An Optional describing the result
    • hasEqualItemData

      public boolean hasEqualItemData(@Nonnull ItemMeta meta1, @Nonnull ItemMeta meta2)
      This method compares the custom data stored on two ItemMeta objects. This method will only return true if both ItemMetas contain custom data and if both of their data values are equal.
      Parameters:
      meta1 - The first ItemMeta
      meta2 - The second ItemMeta
      Returns:
      Whether both metas have data on them and its the same.