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 newCustomItemDataServicefor the givenPluginand the provided data key. -
Method Summary
Modifier and TypeMethodDescriptiongetItemData(org.bukkit.inventory.ItemStack item) This method returns anOptionalholding 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.NamespacedKeygetKey()booleanhasEqualItemData(org.bukkit.inventory.meta.ItemMeta meta1, org.bukkit.inventory.meta.ItemMeta meta2) This method compares the custom data stored on twoItemMetaobjects.voidsetItemData(org.bukkit.inventory.ItemStack item, String id) This method stores the given id on the providedItemStackvia persistent data.voidsetItemData(org.bukkit.inventory.meta.ItemMeta meta, String id) This method stores the given id on the providedItemMetavia persistent data.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bukkit.Keyed
key
-
Constructor Details
-
CustomItemDataService
This creates a newCustomItemDataServicefor the givenPluginand the provided data key.- Parameters:
plugin- ThePluginfor this service to usekey- The key under which to store data
-
-
Method Details
-
getKey
public org.bukkit.NamespacedKey getKey()- Specified by:
getKeyin interfaceorg.bukkit.Keyed
-
setItemData
This method stores the given id on the providedItemStackvia persistent data.- Parameters:
item- TheItemStackto store data onid- The id to store on theItemStack
-
setItemData
This method stores the given id on the providedItemMetavia persistent data.- Parameters:
meta- TheItemMetato store data onid- The id to store on theItemMeta
-
getItemData
This method returns anOptionalholding the data stored on the givenItemStack. TheOptionalwill be empty if the givenItemStackis null, doesn't have anyItemMetaor if the requested data simply does not exist on thatItemStack.- Parameters:
item- TheItemStackto check- Returns:
- An
Optionaldescribing the result
-
getItemData
This method returns anOptional, either empty or holding the data stored on the givenItemMeta.- Parameters:
meta- TheItemMetato check- Returns:
- An
Optionaldescribing 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 twoItemMetaobjects. This method will only return true if bothItemMetas contain custom data and if both of their data values are equal.- Parameters:
meta1- The firstItemMetameta2- The secondItemMeta- Returns:
- Whether both metas have data on them and its the same.
-