Item Manager - C00kier/CookiersLib GitHub Wiki
Utility class for managing and modifying ItemStack objects in Bukkit/Spigot plugins. It includes functionality for enchantments, metadata, namespaced keys, display properties, and inventory comparisons.
Applies the specified enchantments to the given item meta. Overwrites existing ones.
applyEnchantmentsToItemMeta(ItemMeta meta, Map<Enchantment, Integer> enchantmentsWithLevels)
Parameters:
-
meta
- The item meta to apply enchantments to. -
enchantmentsWithLevels
- Enchantments and their levels.
Applies enchantments directly to the item stack by modifying its meta.
applyEnchantmentsToItemStack(ItemStack itemStack, Map<Enchantment, Integer> enchantmentsWithLevels)
Parameters:
-
itemStack
- The item to enchant. -
enchantmentsWithLevels
- Enchantments and levels to apply.
Stores custom metadata in the item meta using the Bukkit PersistentDataContainer.
addNamespacedKeyToItemMeta(JavaPlugin plugin, ItemMeta meta, String key, PersistentDataType<T, Z> dataType, Z value)
Parameters:
-
plugin
— your plugin instance -
meta
— the item meta to store the data in -
key
— the namespaced key (without namespace) -
dataType
— the data type of the value (e.g. STRING, INTEGER) -
value
— the value to store
Applies a namespaced key directly to an item.
addNamespacedKeyToItemStack(JavaPlugin plugin, ItemStack itemStack, String key, PersistentDataType<T, Z> dataType, Z value)
Parameters:
-
plugin
— your plugin instanc -
itemStack
— the item to modify -
key
— the namespaced key -
dataType
— the type used to store the value -
value
— the actual value to store
Reads a namespaced value stored in an item.
getNamespacedKeyValueFromItemStack(JavaPlugin plugin, ItemStack itemStack, String key, PersistentDataType<T, Z> dataType)
Parameters:
-
plugin
— your plugin instance -
itemStack
— the item to check -
key
— the namespaced key -
dataType
— the expected data type
Returns:
- The
stored value
, ornull
if not found
Checks if an item has a specific value stored under a key.
doesItemStackContainValueForNamespacedKey(JavaPlugin plugin, ItemStack itemStack, String key, PersistentDataType<T, Z> dataType, Z expectedValue)
Parameters:
-
plugin
— your plugin instance -
itemStack
— the item to check -
key
— the namespaced key -
dataType
— the data type -
expectedValue
— the value to compare against
Returns:
-
true
if the stored value matches,false
otherwise
Checks whether an ItemStack contains a persistent data value for the given key and data type, namespaced under the plugin.
hasNamespacedKey(JavaPlugin plugin, ItemStack itemStack, String key, PersistentDataType<T, Z> type)
Parameters:
-
plugin
— your plugin instance, used for namespacing the key -
itemStack
— the item to check -
key
— the key to look for, under the plugin's namespace -
type
— the expected persistent data type (e.g., PersistentDataType.STRING)
Returns:
-
true
if the item has the specified persistent key with the correct type,false
otherwise
Sets the visible name of the item.
setDisplayNameToItemStack(ItemStack itemStack, String displayName)
Parameters:
-
itemStack
— the item to modify -
displayName
— the name to set
Sets the display name to an invisible placeholder.
setEmptyStringAsDisplayName(ItemStack itemStack)
Parameters:
-
itemStack
— the item to modify
Sets the item's lore.
setLoreToItemStack(ItemStack itemStack, List<String> lore)
Parameters:
-
itemStack
— the item to modify -
lore
— the lines of lore
Checks whether two items have exactly the same enchantments.
hasItemStacksSameEnchantments(ItemStack item1, ItemStack item2)
Parameters:
-
item1
— first item -
item2
— second item
Returns:
-
true
if enchantments are identical,false
otherwise
Checks if two lists contain the same items and total amounts, regardless of stack sizes.
areItemStackListsEqual(List<ItemStack> list1, List<ItemStack> list2)
Parameters:
-
list1
— first list of items -
list2
— second list of items
Returns:
-
true
if both lists are equivalent,false
otherwise