Class CustomItemDataService

java.lang.Object
io.github.thebusybiscuit.slimefun4.core.services.CustomItemDataService
All Implemented Interfaces:
net.kyori.adventure.key.Keyed, org.bukkit.Keyed

public class CustomItemDataService extends Object implements org.bukkit.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 Summary

    Constructors
    Constructor
    Description
    CustomItemDataService(org.bukkit.plugin.Plugin plugin, String key)
    This creates a new CustomItemDataService for the given Plugin and the provided data key.
  • Method Summary

    Modifier and Type
    Method
    Description
    getItemData(org.bukkit.inventory.ItemStack item)
    This method returns an Optional holding the data stored on the given ItemStack.
    getItemData(org.bukkit.inventory.meta.ItemMeta meta)
    This method returns an Optional, either empty or holding the data stored on the given ItemMeta.
    org.bukkit.NamespacedKey
     
    boolean
    hasEqualItemData(org.bukkit.inventory.meta.ItemMeta meta1, org.bukkit.inventory.meta.ItemMeta meta2)
    This method compares the custom data stored on two ItemMeta objects.
    void
    setItemData(org.bukkit.inventory.ItemStack item, String id)
    This method stores the given id on the provided ItemStack via persistent data.
    void
    setItemData(org.bukkit.inventory.meta.ItemMeta meta, String id)
    This method stores the given id on the provided ItemMeta via persistent data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.bukkit.Keyed

    key
  • Constructor Details

    • CustomItemDataService

      public CustomItemDataService(@Nonnull org.bukkit.plugin.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 org.bukkit.NamespacedKey getKey()
      Specified by:
      getKey in interface org.bukkit.Keyed
    • setItemData

      public void setItemData(@Nonnull org.bukkit.inventory.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 org.bukkit.inventory.meta.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 org.bukkit.inventory.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 org.bukkit.inventory.meta.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 org.bukkit.inventory.meta.ItemMeta meta1, @Nonnull org.bukkit.inventory.meta.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.