Class CustomItemDataService
java.lang.Object
io.github.thebusybiscuit.slimefun4.core.services.CustomItemDataService
- All Implemented Interfaces:
net.kyori.adventure.key.Keyed
,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
ConstructorsConstructorDescriptionCustomItemDataService
(org.bukkit.plugin.Plugin plugin, String key) This creates a newCustomItemDataService
for the givenPlugin
and the provided data key. -
Method Summary
Modifier and TypeMethodDescriptiongetItemData
(org.bukkit.inventory.ItemStack item) This method returns anOptional
holding the data stored on the givenItemStack
.getItemData
(org.bukkit.inventory.meta.ItemMeta meta) This method returns anOptional
, either empty or holding the data stored on the givenItemMeta
.org.bukkit.NamespacedKey
getKey()
boolean
hasEqualItemData
(org.bukkit.inventory.meta.ItemMeta meta1, org.bukkit.inventory.meta.ItemMeta meta2) This method compares the custom data stored on twoItemMeta
objects.void
setItemData
(org.bukkit.inventory.ItemStack item, String id) This method stores the given id on the providedItemStack
via persistent data.void
setItemData
(org.bukkit.inventory.meta.ItemMeta meta, String id) This method stores the given id on the providedItemMeta
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
This creates a newCustomItemDataService
for the givenPlugin
and the provided data key.- Parameters:
plugin
- ThePlugin
for this service to usekey
- The key under which to store data
-
-
Method Details
-
getKey
public org.bukkit.NamespacedKey getKey()- Specified by:
getKey
in interfaceorg.bukkit.Keyed
-
setItemData
This method stores the given id on the providedItemStack
via persistent data.- Parameters:
item
- TheItemStack
to store data onid
- The id to store on theItemStack
-
setItemData
This method stores the given id on the providedItemMeta
via persistent data.- Parameters:
meta
- TheItemMeta
to store data onid
- The id to store on theItemMeta
-
getItemData
This method returns anOptional
holding the data stored on the givenItemStack
. TheOptional
will be empty if the givenItemStack
is null, doesn't have anyItemMeta
or if the requested data simply does not exist on thatItemStack
.- Parameters:
item
- TheItemStack
to check- Returns:
- An
Optional
describing the result
-
getItemData
This method returns anOptional
, either empty or holding the data stored on the givenItemMeta
.- Parameters:
meta
- TheItemMeta
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 twoItemMeta
objects. This method will only return true if bothItemMeta
s contain custom data and if both of their data values are equal.- Parameters:
meta1
- The firstItemMeta
meta2
- The secondItemMeta
- Returns:
- Whether both metas have data on them and its the same.
-