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.


Add enchantments to Item Meta

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.

Add enchantments to Item Stack

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.

Add namespaced key to Item Meta

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

Add namespaced key to Item Stack

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

Get namespaced value from Item Stack

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, or null if not found

Check if Item Stack has specific value under a key

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

Check if Item Stack has specific Persistent Data for given namespaced key

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

Set display name to Item Stack

Sets the visible name of the item.

setDisplayNameToItemStack(ItemStack itemStack, String displayName)

Parameters:

  • itemStack — the item to modify
  • displayName — the name to set

Set empty display name

Sets the display name to an invisible placeholder.

setEmptyStringAsDisplayName(ItemStack itemStack)

Parameters:

  • itemStack — the item to modify

Set Lore To Item Stack

Sets the item's lore.

setLoreToItemStack(ItemStack itemStack, List<String> lore)

Parameters:

  • itemStack — the item to modify
  • lore — the lines of lore

Check if 2 Item Stacks has same enchantments

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

Are 2 Item Stacks List equal

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
⚠️ **GitHub.com Fallback** ⚠️