Class ItemBuilder
java.lang.Object
io.github.lucfr1746.llibrary.itemstack.ItemBuilder
- Direct Known Subclasses:
ArmorBuilder
,AxolotlBucketBuilder
,BannerBuilder
,BundleBuilder
,CompassBuilder
,CrossbowBuilder
,DamageableItemBuilder
,EnchantmentStorageBuilder
,FireworkBuilder
,FireworkEffectBuilder
,KnowledgeBookBuilder
,LeatherArmorBuilder
,MapBuilder
,MusicInstrumentBuilder
,OminousBottleBuilder
,PotionBuilder
,RepairableBuilder
,ShieldBuilder
,SkullBuilder
,SpawnEggBuilder
,SuspiciousStewBuilder
,TropicalFishBucketBuilder
,WritableBookBuilder
A utility class for building and modifying
ItemStack
objects in Minecraft.
Supports setting item material, amount, display names, and more.-
Constructor Summary
ConstructorsConstructorDescriptionItemBuilder
(@NotNull org.bukkit.Material material) Creates an ItemBuilder with a specifiedMaterial
and a default amount of 1.ItemBuilder
(@NotNull org.bukkit.Material material, int amount) Creates an ItemBuilder with a specifiedMaterial
and amount.ItemBuilder
(@NotNull org.bukkit.inventory.ItemStack itemStack) Creates an ItemBuilder from an existingItemStack
. -
Method Summary
Modifier and TypeMethodDescriptionaddAttributeModifier
(@NotNull org.bukkit.attribute.Attribute attribute, @NotNull org.bukkit.attribute.AttributeModifier modifier) Add an Attribute and it's Modifier.addEnchant
(@NotNull org.bukkit.enchantments.Enchantment enchantment) Adds an enchantment to the item with level 1 and level limit check.addEnchant
(@NotNull org.bukkit.enchantments.Enchantment enchantment, int level) Adds or updates an enchantment on the item with level limit check.addEnchant
(@NotNull org.bukkit.enchantments.Enchantment enchantment, int level, boolean ignoreLevelLimit) Adds or updates an enchantment on the item.addItemFlags
(@NotNull org.bukkit.inventory.ItemFlag... itemFlags) Adds the specified item flags to the item.Adds a single lore line to the item.@NotNull org.bukkit.inventory.ItemStack
build()
Builds and returns the finalItemStack
.int
Gets the number of items in the stack.@Nullable com.google.common.collect.Multimap
<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> Return an immutable copy of all Attributes and their modifiers in this ItemMeta.@Nullable Collection
<org.bukkit.attribute.AttributeModifier> getAttributeModifiers
(@NotNull org.bukkit.attribute.Attribute attribute) Return an immutable copy of allAttributeModifier
s for a givenAttribute
@NotNull com.google.common.collect.Multimap
<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> getAttributeModifiers
(@NotNull org.bukkit.inventory.EquipmentSlot slot) Return an immutable copy of allAttribute
s and theirAttributeModifier
s for a givenEquipmentSlot
.int
Gets the Custom Model Data of the item.@Nullable org.bukkit.Tag
<org.bukkit.damage.DamageType> Gets the damage resistance tag of the item.Gets the display name of the item.int
Gets the enchantable value of the item.int
getEnchantLevel
(@NotNull org.bukkit.enchantments.Enchantment enchantment) Gets the level of a specific enchantment on the item.@Nullable Boolean
Gets the enchantment glint override status of the item.Gets all enchantments on the item.@NotNull org.bukkit.inventory.meta.components.EquippableComponent
Gets the equippable component of the item.@NotNull org.bukkit.inventory.meta.components.FoodComponent
Gets the food component associated with this item, or creates an empty food instance.@NotNull Set
<org.bukkit.inventory.ItemFlag> Gets all item flags present on the item.@NotNull org.bukkit.inventory.meta.ItemMeta
@Nullable org.bukkit.NamespacedKey
Gets the item model of the item.@Nullable org.bukkit.inventory.meta.components.JukeboxPlayableComponent
Gets the JukeboxPlayableComponent of the item.int
Gets the max stack size of the item.@NotNull org.bukkit.inventory.ItemRarity
Gets the rarity of the item.@NotNull org.bukkit.inventory.meta.components.ToolComponent
Gets theToolComponent
of the item.@Nullable org.bukkit.NamespacedKey
Gets the tooltip style of the item.@NotNull String
Gets the translation key for this item, used for localization.@NotNull org.bukkit.Material
getType()
Gets the type of material of the item stack.@NotNull org.bukkit.inventory.meta.components.UseCooldownComponent
Gets the cooldown component associated with this item, or creates an empty cooldown instance.@Nullable org.bukkit.inventory.ItemStack
Gets the item that remains after using this item, if any.boolean
Checks if the ItemMeta has any attribute modifiers.boolean
hasConflictingEnchant
(@NotNull org.bukkit.enchantments.Enchantment enchantment) Checks if an enchantment conflicts with any existing enchantments on the item.boolean
Checks if the item has a Custom Model Data set.boolean
Checks if the item has damage resistance.boolean
hasEnchant
(@NotNull org.bukkit.enchantments.Enchantment enchantment) Checks if the item has a specific enchantment.boolean
Checks if the item has an enchantable value set.boolean
Checks if the item has an enchantment glint override.boolean
Checks if the item has any enchantments.boolean
Checks whether the item has an equippable component.boolean
Checks if the item has a food component.boolean
hasItemFlag
(@NotNull org.bukkit.inventory.ItemFlag flag) Checks if a specific item flag is present on the item.boolean
Checks if the item has a custom item model.boolean
Checks if the item has a JukeboxPlayableComponent.boolean
Checks if the item has a custom max stack size.boolean
Checks if the item has a custom rarity.boolean
Checks if the item has aToolComponent
attached.boolean
Checks if the item has a tooltip style.boolean
Checks if the item has a use cooldown component.boolean
Checks if the item has a use remainder.Hides all item flags from the item.insertLore
(@NotNull String lore, int index) Inserts a lore line at a specified index.boolean
isGlider()
Checks if the item is a glider.boolean
Checks if the item has tooltips hidden.boolean
Checks if the item is unbreakable.removeAttributeModifier
(@NotNull org.bukkit.attribute.Attribute attribute) Remove allAttributeModifier
s associated with the givenAttribute
.removeAttributeModifier
(@NotNull org.bukkit.attribute.Attribute attribute, @NotNull org.bukkit.attribute.AttributeModifier modifier) Remove a specificAttribute
andAttributeModifier
.removeAttributeModifier
(@NotNull org.bukkit.inventory.EquipmentSlot slot) Remove allAttribute
s andAttributeModifier
s for a givenEquipmentSlot
.removeEnchant
(@NotNull org.bukkit.enchantments.Enchantment enchantment) Removes a specific enchantment from the item.Removes all enchantments from the item.removeItemFlags
(@NotNull org.bukkit.inventory.ItemFlag... itemFlags) Removes the specified item flags from the item.replaceLore
(@NotNull String from, @NotNull String to) Replaces occurrences of a specific substring in the item's lore.setAmount
(int amount) Sets the number of items in the stack.setAttributeModifiers
(@Nullable com.google.common.collect.Multimap<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> attributeModifiers) Set allAttribute
s and theirAttributeModifier
s.setCustomModelData
(Integer data) Sets the Custom Model Data for the item.setDamageResistant
(@Nullable org.bukkit.Tag<org.bukkit.damage.DamageType> tag) Sets the damage resistance tag of the item.setDisplayName
(String name) Sets the display name of the item.setEnchantable
(@Nullable Integer enchantable) Sets the enchantable value of the item.setEnchantmentGlintOverride
(@Nullable Boolean override) Sets or removes the enchantment glint override.setEquippableComponent
(org.bukkit.inventory.EquipmentSlot equipmentSlot) Creates and sets a custom equippable component for the item using the specified equipment slot.setEquippableComponent
(@Nullable org.bukkit.inventory.meta.components.EquippableComponent equippable) Sets the equippable component for the item.setFood
(int nutrition, float saturation, boolean canEatOnFull) Creates and sets a custom food component for this item.setFoodComponent
(@Nullable org.bukkit.inventory.meta.components.FoodComponent food) Sets the food component for this item.setGlider
(boolean glider) Sets the glider status of the item.setHideTooltip
(boolean hideTooltip) Sets whether tooltips should be hidden for the item.setItemModel
(@NotNull String value) Sets the item model of the item using a string.setItemModel
(@Nullable org.bukkit.NamespacedKey itemModel) Sets the item model of the item.setJukeboxPlayableComponent
(String keyValue, org.bukkit.JukeboxSong jukeboxSong, boolean showInTooltip) Creates and sets a custom JukeboxPlayableComponent using a key value string, song, and tooltip visibility.setJukeboxPlayableComponent
(@Nullable org.bukkit.inventory.meta.components.JukeboxPlayableComponent jukeboxPlayable) Sets the JukeboxPlayableComponent of the item.setJukeboxPlayableComponent
(org.bukkit.NamespacedKey songKey, org.bukkit.JukeboxSong jukeboxSong, boolean showInTooltip) Creates and sets a custom JukeboxPlayableComponent using a song key, song, and tooltip visibility.Sets the lore of the item using an array of strings.Sets the lore of the item using a list of strings.setMaxStackSize
(@Nullable Integer max) Sets the max stack size of the item.setRarity
(@Nullable org.bukkit.inventory.ItemRarity rarity) Sets the rarity of the item.setToolComponent
(float defaultMiningSpeed, int damagePerBlock) Creates and sets a newCustomToolComponent
for the item with the specified default mining speed and damage per block.setToolComponent
(@Nullable org.bukkit.inventory.meta.components.ToolComponent tool) Sets theToolComponent
for the item.setTooltipStyle
(@NotNull String value) Sets the tooltip style of the item using a string.setTooltipStyle
(@Nullable org.bukkit.NamespacedKey tooltipStyle) Sets the tooltip style of the item.setType
(@NotNull org.bukkit.Material material) Sets the type of the item stack.setUnbreakable
(boolean unbreakable) Sets the unbreakable status of the item.setUseCooldownComponent
(float cooldownSeconds, @NotNull String keyValue) Creates and sets a custom use cooldown for this item using a string value for the namespace key.setUseCooldownComponent
(float cooldownSeconds, @NotNull org.bukkit.NamespacedKey cooldownGroup) Sets a custom use cooldown for this item.setUseCooldownComponent
(@Nullable org.bukkit.inventory.meta.components.UseCooldownComponent cooldown) Sets the cooldown component for this item.setUseRemainder
(@Nullable org.bukkit.inventory.ItemStack remainder) Sets the item that will remain after using this item.
-
Constructor Details
-
ItemBuilder
public ItemBuilder(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack) Creates an ItemBuilder from an existingItemStack
.- Parameters:
itemStack
- the ItemStack to clone and modify- Throws:
NullPointerException
- if itemStack is null
-
ItemBuilder
public ItemBuilder(@NotNull @NotNull org.bukkit.Material material, int amount) Creates an ItemBuilder with a specifiedMaterial
and amount.- Parameters:
material
- the material of the itemamount
- the quantity of items (must be between 1 and 127)- Throws:
IllegalArgumentException
- if the amount is less than 1 or greater than 127NullPointerException
- if material is null
-
ItemBuilder
public ItemBuilder(@NotNull @NotNull org.bukkit.Material material) Creates an ItemBuilder with a specifiedMaterial
and a default amount of 1.- Parameters:
material
- the material of the item- Throws:
IllegalArgumentException
- if material is airNullPointerException
- if material is null
-
-
Method Details
-
build
@NotNull public @NotNull org.bukkit.inventory.ItemStack build()Builds and returns the finalItemStack
.- Returns:
- a clone of the constructed ItemStack
-
setAmount
Sets the number of items in the stack.- Parameters:
amount
- the number of items must be between 1 and 127 (inclusive)- Returns:
- this ItemBuilder instance for method chaining
- Throws:
IllegalArgumentException
- if the amount is less than 1 or greater than 127
-
getAmount
public int getAmount()Gets the number of items in the stack.- Returns:
- the number of items in the stack
-
setType
Sets the type of the item stack.- Parameters:
material
- the material to set, must not be air- Returns:
- this ItemBuilder instance for method chaining
- Throws:
IllegalArgumentException
- if the material is air
-
getType
@NotNull public @NotNull org.bukkit.Material getType()Gets the type of material of the item stack.- Returns:
- the material type of the item stack
-
getTranslationKey
Gets the translation key for this item, used for localization.- Returns:
- the translation key for the item
-
setDisplayName
Sets the display name of the item.- Parameters:
name
- the new display name can be null to remove the display name- Returns:
- the current ItemBuilder instance for method chaining
-
getDisplayName
Gets the display name of the item.- Returns:
- the display name if a set, or the default item translation key if not
-
setLores
Sets the lore of the item using a list of strings.- Parameters:
lores
- the list of lore strings to set- Returns:
- the current ItemBuilder instance for method chaining
-
setLores
Sets the lore of the item using an array of strings.- Parameters:
lores
- the array of lore strings to set- Returns:
- the current ItemBuilder instance for method chaining
-
replaceLore
Replaces occurrences of a specific substring in the item's lore.- Parameters:
from
- the substring to replaceto
- the substring to replace with- Returns:
- the current ItemBuilder instance for method chaining
-
addLore
Adds a single lore line to the item.- Parameters:
lore
- the lore string to add- Returns:
- the current ItemBuilder instance for method chaining
-
insertLore
Inserts a lore line at a specified index.- Parameters:
lore
- the lore string to insertindex
- the position to insert the lore at- Returns:
- the current ItemBuilder instance for method chaining
- Throws:
IllegalArgumentException
- if the index is negative
-
hasCustomModelData
public boolean hasCustomModelData()Checks if the item has a Custom Model Data set.- Returns:
- true if the item has Custom Model Data, false otherwise
-
getCustomModelData
public int getCustomModelData()Gets the Custom Model Data of the item.- Returns:
- the Custom Model Data value
- Throws:
IllegalArgumentException
- if the item does not have Custom Model Data
-
setCustomModelData
Sets the Custom Model Data for the item.- Parameters:
data
- the Custom Model Data to set, or null to remove it- Returns:
- the current ItemBuilder instance for method chaining
-
hasEnchantable
public boolean hasEnchantable()Checks if the item has an enchantable value set.- Returns:
- true if the item has an enchantable value, false otherwise
-
getEnchantable
public int getEnchantable()Gets the enchantable value of the item.- Returns:
- the enchantable value
-
setEnchantable
Sets the enchantable value of the item. If null is provided, the enchantable value will be removed.- Parameters:
enchantable
- the enchantable value to set, or null to remove it- Returns:
- the current ItemBuilder instance for method chaining
-
hasEnchants
public boolean hasEnchants()Checks if the item has any enchantments.- Returns:
- true if the item has enchantments, false otherwise
-
hasEnchant
public boolean hasEnchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment) Checks if the item has a specific enchantment.- Parameters:
enchantment
- the enchantment to check for- Returns:
- true if the item has the specified enchantment, false otherwise
-
getEnchantLevel
public int getEnchantLevel(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment) Gets the level of a specific enchantment on the item.- Parameters:
enchantment
- the enchantment to check- Returns:
- the level of the enchantment
-
getEnchants
Gets all enchantments on the item.- Returns:
- a map of enchantments and their levels
-
addEnchant
public ItemBuilder addEnchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment, int level, boolean ignoreLevelLimit) Adds or updates an enchantment on the item. If the level is 0, the enchantment will be removed.- Parameters:
enchantment
- the enchantment to add or updatelevel
- the level of the enchantmentignoreLevelLimit
- whether to bypass level restrictions- Returns:
- the current ItemBuilder instance for method chaining
-
addEnchant
public ItemBuilder addEnchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment, int level) Adds or updates an enchantment on the item with level limit check.- Parameters:
enchantment
- the enchantment to add or updatelevel
- the level of the enchantment- Returns:
- the current ItemBuilder instance for method chaining
-
addEnchant
Adds an enchantment to the item with level 1 and level limit check.- Parameters:
enchantment
- the enchantment to add- Returns:
- the current ItemBuilder instance for method chaining
-
removeEnchant
Removes a specific enchantment from the item.- Parameters:
enchantment
- the enchantment to remove- Returns:
- the current ItemBuilder instance for method chaining
-
removeEnchants
Removes all enchantments from the item.- Returns:
- the current ItemBuilder instance for method chaining
-
hasConflictingEnchant
public boolean hasConflictingEnchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment) Checks if an enchantment conflicts with any existing enchantments on the item.- Parameters:
enchantment
- the enchantment to check- Returns:
- true if there is a conflict, false otherwise
-
addItemFlags
Adds the specified item flags to the item. If HIDE_ATTRIBUTES are added and Paper API is available, default attributes are set.- Parameters:
itemFlags
- the item flags to add- Returns:
- the current ItemBuilder instance for method chaining
-
removeItemFlags
Removes the specified item flags from the item. If HIDE_ATTRIBUTES are removed and Paper API is available, default attributes are cleared.- Parameters:
itemFlags
- the item flags to remove- Returns:
- the current ItemBuilder instance for method chaining
-
hideAllItemFlags
Hides all item flags from the item. If Paper API is available and the item has no attribute modifiers, default attributes are set.- Returns:
- the current ItemBuilder instance for method chaining
-
getItemFlags
Gets all item flags present on the item.- Returns:
- a set of item flags
-
hasItemFlag
public boolean hasItemFlag(@NotNull @NotNull org.bukkit.inventory.ItemFlag flag) Checks if a specific item flag is present on the item.- Parameters:
flag
- the item flag to check for- Returns:
- true if the item contains the specified flag, false otherwise
-
isHideTooltip
public boolean isHideTooltip()Checks if the item has tooltips hidden.- Returns:
- true if tooltips are hidden, false otherwise
-
setHideTooltip
Sets whether tooltips should be hidden for the item.- Parameters:
hideTooltip
- true to hide tooltips, false to show them- Returns:
- the current ItemBuilder instance for method chaining
-
hasTooltipStyle
public boolean hasTooltipStyle()Checks if the item has a tooltip style.- Returns:
- true if the item has a tooltip style, false otherwise
-
getTooltipStyle
@Nullable public @Nullable org.bukkit.NamespacedKey getTooltipStyle()Gets the tooltip style of the item.- Returns:
- the tooltip style as a NamespacedKey, or null if not set
-
setTooltipStyle
Sets the tooltip style of the item.- Parameters:
tooltipStyle
- the NamespacedKey for the tooltip style, or null to remove it- Returns:
- the current ItemBuilder instance for method chaining
-
setTooltipStyle
Sets the tooltip style of the item using a string. If the string does not contain a namespace, "minecraft" is used by default.- Parameters:
value
- the string representing the tooltip style- Returns:
- the current ItemBuilder instance for method chaining
-
hasItemModel
public boolean hasItemModel()Checks if the item has a custom item model.- Returns:
- true if the item has a custom item model, false otherwise
-
getItemModel
@Nullable public @Nullable org.bukkit.NamespacedKey getItemModel()Gets the item model of the item.- Returns:
- the item model as a NamespacedKey, or null if not set
-
setItemModel
Sets the item model of the item.- Parameters:
itemModel
- the NamespacedKey for the item model, or null to remove it- Returns:
- the current ItemBuilder instance for method chaining
-
setItemModel
Sets the item model of the item using a string. If the string does not contain a namespace, "minecraft" is used by default.- Parameters:
value
- the string representing the item model- Returns:
- the current ItemBuilder instance for method chaining
-
isUnbreakable
public boolean isUnbreakable()Checks if the item is unbreakable.- Returns:
- true if the item is unbreakable, false otherwise
-
setUnbreakable
Sets the unbreakable status of the item.- Parameters:
unbreakable
- true to make the item unbreakable, false otherwise- Returns:
- the current ItemBuilder instance for method chaining
-
hasEnchantmentGlintOverride
public boolean hasEnchantmentGlintOverride()Checks if the item has an enchantment glint override.- Returns:
- true, if the item has an enchantment glint override, false otherwise
-
getEnchantmentGlintOverride
Gets the enchantment glint override status of the item.- Returns:
- true if the glint is overridden, false if not, or null if unset
-
setEnchantmentGlintOverride
Sets or removes the enchantment glint override.- Parameters:
override
- true to enable the glint, false to disable it, or null to remove the override- Returns:
- the current ItemBuilder instance for method chaining
-
isGlider
public boolean isGlider()Checks if the item is a glider.- Returns:
- true if the item is a glider, false otherwise
-
setGlider
Sets the glider status of the item.- Parameters:
glider
- true to make the item a glider, false otherwise- Returns:
- the current ItemBuilder instance for method chaining
-
hasDamageResistant
public boolean hasDamageResistant()Checks if the item has damage resistance.- Returns:
- true if the item has damage resistance, false otherwise
-
getDamageResistant
@Nullable public @Nullable org.bukkit.Tag<org.bukkit.damage.DamageType> getDamageResistant()Gets the damage resistance tag of the item.- Returns:
- the damage resistance tag as a
org.bukkit.Tag<org.bukkit.damage.DamageType>
, or null if not set
-
setDamageResistant
public ItemBuilder setDamageResistant(@Nullable @Nullable org.bukkit.Tag<org.bukkit.damage.DamageType> tag) Sets the damage resistance tag of the item.- Parameters:
tag
- theorg.bukkit.Tag<org.bukkit.damage.DamageType>
for damage resistance, or null to remove it- Returns:
- the current ItemBuilder instance for method chaining
-
hasMaxStackSize
public boolean hasMaxStackSize()Checks if the item has a custom max stack size.- Returns:
- true if the item has a custom max stack size, false otherwise
-
getMaxStackSize
public int getMaxStackSize()Gets the max stack size of the item.- Returns:
- the max stack size, or the default stack size if not set
-
setMaxStackSize
Sets the max stack size of the item.- Parameters:
max
- the new max stack size, or null to reset to the default stack size- Returns:
- the current ItemBuilder instance for method chaining
- Throws:
IllegalArgumentException
- if the max stack size is not between 1 and 99
-
hasRarity
public boolean hasRarity()Checks if the item has a custom rarity.- Returns:
- true if the item has a custom rarity, false otherwise
-
getRarity
@NotNull public @NotNull org.bukkit.inventory.ItemRarity getRarity()Gets the rarity of the item.- Returns:
- the item's rarity, or ItemRarity. COMMON if not set
-
setRarity
Sets the rarity of the item.- Parameters:
rarity
- the ItemRarity to set, or null to remove the custom rarity- Returns:
- the current ItemBuilder instance for method chaining
-
hasUseRemainder
public boolean hasUseRemainder()Checks if the item has a use remainder.- Returns:
- true if the item has a use remainder, false otherwise.
-
getUseRemainder
@Nullable public @Nullable org.bukkit.inventory.ItemStack getUseRemainder()Gets the item that remains after using this item, if any.- Returns:
- the remainder ItemStack, or null if there is none.
-
setUseRemainder
Sets the item that will remain after using this item.- Parameters:
remainder
- the ItemStack to set as the use remainder, or null to remove it.- Returns:
- the current ItemBuilder instance for chaining.
-
hasUseCooldownComponent
public boolean hasUseCooldownComponent()Checks if the item has a use cooldown component.- Returns:
- true if the item has a use cooldown, false otherwise.
-
getUseCooldownComponent
@NotNull public @NotNull org.bukkit.inventory.meta.components.UseCooldownComponent getUseCooldownComponent()Gets the cooldown component associated with this item, or creates an empty cooldown instance.- Returns:
- the UseCooldownComponent set on this item, or creates an empty cooldown instance.
-
setUseCooldownComponent
public ItemBuilder setUseCooldownComponent(@Nullable @Nullable org.bukkit.inventory.meta.components.UseCooldownComponent cooldown) Sets the cooldown component for this item.- Parameters:
cooldown
- the UseCooldownComponent to set, or null to remove the cooldown.- Returns:
- the current ItemBuilder instance for chaining.
-
setUseCooldownComponent
public ItemBuilder setUseCooldownComponent(float cooldownSeconds, @NotNull @NotNull org.bukkit.NamespacedKey cooldownGroup) Sets a custom use cooldown for this item.- Parameters:
cooldownSeconds
- the cooldown duration in seconds.cooldownGroup
- the NamespacedKey representing the cooldown group.- Returns:
- the current ItemBuilder instance for chaining.
-
setUseCooldownComponent
public ItemBuilder setUseCooldownComponent(float cooldownSeconds, @NotNull @NotNull String keyValue) Creates and sets a custom use cooldown for this item using a string value for the namespace key.- Parameters:
cooldownSeconds
- the cooldown duration in seconds.keyValue
- the string representation of the NamespacedKey.- Returns:
- the current ItemBuilder instance for chaining.
-
hasFoodComponent
public boolean hasFoodComponent()Checks if the item has a food component.- Returns:
- true if the item has a food component, false otherwise.
-
getFoodComponent
@NotNull public @NotNull org.bukkit.inventory.meta.components.FoodComponent getFoodComponent()Gets the food component associated with this item, or creates an empty food instance.- Returns:
- the FoodComponent, or creates an empty food instance.
-
setFoodComponent
public ItemBuilder setFoodComponent(@Nullable @Nullable org.bukkit.inventory.meta.components.FoodComponent food) Sets the food component for this item.- Parameters:
food
- the FoodComponent to set, or null to remove it.- Returns:
- the current ItemBuilder instance for chaining.
-
setFood
Creates and sets a custom food component for this item.- Parameters:
nutrition
- the amount of nutrition the food provides.saturation
- the saturation modifier of the food.canEatOnFull
- whether the food can be eaten even if the player is not hungry.- Returns:
- the current ItemBuilder instance for chaining.
-
hasToolComponent
public boolean hasToolComponent()Checks if the item has aToolComponent
attached.- Returns:
- true if the item has a ToolComponent, false otherwise
-
getToolComponent
@NotNull public @NotNull org.bukkit.inventory.meta.components.ToolComponent getToolComponent()Gets theToolComponent
of the item.- Returns:
- the ToolComponent associated with this item
- Throws:
NullPointerException
- if the item does not have a ToolComponent
-
setToolComponent
public ItemBuilder setToolComponent(@Nullable @Nullable org.bukkit.inventory.meta.components.ToolComponent tool) Sets theToolComponent
for the item.- Parameters:
tool
- the ToolComponent to set, or null to remove the existing ToolComponent- Returns:
- this ItemBuilder instance for method chaining
-
setToolComponent
Creates and sets a newCustomToolComponent
for the item with the specified default mining speed and damage per block.- Parameters:
defaultMiningSpeed
- the default mining speed of the tooldamagePerBlock
- the amount of damage the tool takes per block broken- Returns:
- this ItemBuilder instance for method chaining
-
hasEquippableComponent
public boolean hasEquippableComponent()Checks whether the item has an equippable component.- Returns:
- true if the item has an equippable component, false otherwise
-
getEquippableComponent
@NotNull public @NotNull org.bukkit.inventory.meta.components.EquippableComponent getEquippableComponent()Gets the equippable component of the item.- Returns:
- the equippable component, never null
-
setEquippableComponent
public ItemBuilder setEquippableComponent(@Nullable @Nullable org.bukkit.inventory.meta.components.EquippableComponent equippable) Sets the equippable component for the item.- Parameters:
equippable
- the equippable component to set, or null to remove it- Returns:
- the current ItemBuilder instance for chaining
-
setEquippableComponent
Creates and sets a custom equippable component for the item using the specified equipment slot.- Parameters:
equipmentSlot
- the slot where the item can be equipped- Returns:
- the current ItemBuilder instance for chaining
-
hasJukeboxPlayableComponent
public boolean hasJukeboxPlayableComponent()Checks if the item has a JukeboxPlayableComponent.- Returns:
- true if the item has a JukeboxPlayableComponent, false otherwise
-
getJukeboxPlayableComponent
@Nullable public @Nullable org.bukkit.inventory.meta.components.JukeboxPlayableComponent getJukeboxPlayableComponent()Gets the JukeboxPlayableComponent of the item.- Returns:
- the JukeboxPlayableComponent, or null if not present
-
setJukeboxPlayableComponent
public ItemBuilder setJukeboxPlayableComponent(@Nullable @Nullable org.bukkit.inventory.meta.components.JukeboxPlayableComponent jukeboxPlayable) Sets the JukeboxPlayableComponent of the item.- Parameters:
jukeboxPlayable
- the JukeboxPlayableComponent to set, or null to remove it- Returns:
- the current ItemBuilder instance for chaining
-
setJukeboxPlayableComponent
public ItemBuilder setJukeboxPlayableComponent(org.bukkit.NamespacedKey songKey, org.bukkit.JukeboxSong jukeboxSong, boolean showInTooltip) Creates and sets a custom JukeboxPlayableComponent using a song key, song, and tooltip visibility.- Parameters:
songKey
- the key identifying the songjukeboxSong
- the JukeboxSong to be playedshowInTooltip
- whether the song should be shown in the item's tooltip- Returns:
- the current ItemBuilder instance for chaining
-
setJukeboxPlayableComponent
public ItemBuilder setJukeboxPlayableComponent(String keyValue, org.bukkit.JukeboxSong jukeboxSong, boolean showInTooltip) Creates and sets a custom JukeboxPlayableComponent using a key value string, song, and tooltip visibility.- Parameters:
keyValue
- the string representation of the song's key (to be converted to a NamespacedKey)jukeboxSong
- the JukeboxSong to be playedshowInTooltip
- whether the song should be shown in the item's tooltip- Returns:
- the current ItemBuilder instance for chaining
-
hasAttributeModifiers
public boolean hasAttributeModifiers()Checks if the ItemMeta has any attribute modifiers.- Returns:
- true if attribute modifiers exist, false otherwise.
-
getAttributeModifiers
@Nullable public @Nullable com.google.common.collect.Multimap<org.bukkit.attribute.Attribute,org.bukkit.attribute.AttributeModifier> getAttributeModifiers()Return an immutable copy of all Attributes and their modifiers in this ItemMeta. Returns null if none exist.- Returns:
- A Multimap containing attributes and their respective modifiers, or null if none exist.
-
getAttributeModifiers
@NotNull public @NotNull com.google.common.collect.Multimap<org.bukkit.attribute.Attribute,org.bukkit.attribute.AttributeModifier> getAttributeModifiers(@NotNull @NotNull org.bukkit.inventory.EquipmentSlot slot) Return an immutable copy of allAttribute
s and theirAttributeModifier
s for a givenEquipmentSlot
. AnyAttributeModifier
that does have a givenEquipmentSlot
will be returned. This is becauseAttributeModifier
s without a slot are active in any slot. If there are no attributes set for the given slot, an empty map will be returned.- Parameters:
slot
- The EquipmentSlot to filter attribute modifiers for.- Returns:
- A non-null Multimap containing attributes and their modifiers for the specified slot.
-
getAttributeModifiers
@Nullable public @Nullable Collection<org.bukkit.attribute.AttributeModifier> getAttributeModifiers(@NotNull @NotNull org.bukkit.attribute.Attribute attribute) Return an immutable copy of allAttributeModifier
s for a givenAttribute
- Parameters:
attribute
- The Attribute to retrieve modifiers for.- Returns:
- A collection of AttributeModifiers associated with the given attribute, or null if none exist.
-
addAttributeModifier
public ItemBuilder addAttributeModifier(@NotNull @NotNull org.bukkit.attribute.Attribute attribute, @NotNull @NotNull org.bukkit.attribute.AttributeModifier modifier) Add an Attribute and it's Modifier. AttributeModifiers can now supportEquipmentSlot
s. If not set, theAttributeModifier
will be active in ALL slots. TwoAttributeModifier
s that have the sameUUID
cannot exist on the same Attribute.- Parameters:
attribute
- The Attribute to modify.modifier
- The AttributeModifier specifying the modification.- Returns:
- The current ItemBuilder instance for method chaining.
-
setAttributeModifiers
public ItemBuilder setAttributeModifiers(@Nullable @Nullable com.google.common.collect.Multimap<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> attributeModifiers) Set allAttribute
s and theirAttributeModifier
s. To clear all currently set Attributes and AttributeModifiers use null or an empty Multimap. If not null nor empty, this will filter all entries that are not null and add them to the ItemStack.- Parameters:
attributeModifiers
- The new Multimap of attributes and their modifiers, or null to clear all modifiers.- Returns:
- The current ItemBuilder instance for method chaining.
-
removeAttributeModifier
public ItemBuilder removeAttributeModifier(@NotNull @NotNull org.bukkit.attribute.Attribute attribute) Remove allAttributeModifier
s associated with the givenAttribute
.- Parameters:
attribute
- The Attribute to remove all modifiers for.- Returns:
- The current ItemBuilder instance for method chaining.
-
removeAttributeModifier
public ItemBuilder removeAttributeModifier(@NotNull @NotNull org.bukkit.inventory.EquipmentSlot slot) Remove allAttribute
s andAttributeModifier
s for a givenEquipmentSlot
. If the givenEquipmentSlot
is null, this will remove allAttributeModifier
s that do not have an EquipmentSlot set.- Parameters:
slot
- The EquipmentSlot to clear all attributes and their modifiers for.- Returns:
- The current ItemBuilder instance for method chaining.
-
removeAttributeModifier
public ItemBuilder removeAttributeModifier(@NotNull @NotNull org.bukkit.attribute.Attribute attribute, @NotNull @NotNull org.bukkit.attribute.AttributeModifier modifier) Remove a specificAttribute
andAttributeModifier
. AttributeModifiers are matched according to theirUUID
.- Parameters:
attribute
- The Attribute to remove the modifier from.modifier
- The specific AttributeModifier to remove.- Returns:
- The current ItemBuilder instance for method chaining.
-
getItemMeta
@NotNull public @NotNull org.bukkit.inventory.meta.ItemMeta getItemMeta()
-