Package com.ultikits.ultitools.utils
Class ItemStackBuilder
java.lang.Object
com.ultikits.ultitools.utils.ItemStackBuilder
A fluent builder for creating ItemStacks with various properties.
- Since:
- 6.2.0
- Version:
- 1.0.0
- Author:
- wisdomme
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionItemStackBuilder(com.cryptomorin.xseries.XMaterial material) Creates a new ItemStackBuilder from an XMaterial.ItemStackBuilder(org.bukkit.inventory.ItemStack itemStack) Creates a new ItemStackBuilder from an existing ItemStack.ItemStackBuilder(org.bukkit.Material material) Creates a new ItemStackBuilder from a Material. -
Method Summary
Modifier and TypeMethodDescriptionAdds lines to the existing lore.amount(int amount) Sets the amount of items in the stack.org.bukkit.inventory.ItemStackbuild()Builds and returns the ItemStack.org.bukkit.inventory.ItemStackBuilds and returns a clone of the ItemStack.customModelData(int data) Sets the custom model data (1.14+).enchant(com.cryptomorin.xseries.XEnchantment enchantment, int level) Adds an enchantment using XEnchantment for cross-version compatibility.enchant(org.bukkit.enchantments.Enchantment enchantment, int level) Adds an enchantment to the item.flags(org.bukkit.inventory.ItemFlag... flags) Adds item flags to the item.glow()Makes the item glow without showing enchantments.hideAll()Hides all item flags.Hides all item attributes.Applies a custom modifier to the item stack.leatherColor(int red, int green, int blue) Sets the color of leather armor using RGB.leatherColor(org.bukkit.Color color) Sets the color of leather armor.Sets the lore of the item.Sets the lore of the item.Applies a custom modifier to the item meta.Sets the display name of the item.static ItemStackBuilderof(com.cryptomorin.xseries.XMaterial material) Creates a new ItemStackBuilder from an XMaterial.static ItemStackBuilderCreates a new ItemStackBuilder from a material name string.static ItemStackBuilderof(org.bukkit.inventory.ItemStack itemStack) Creates a new ItemStackBuilder from an existing ItemStack.static ItemStackBuilderof(org.bukkit.Material material) Creates a new ItemStackBuilder from a Material.removeEnchant(org.bukkit.enchantments.Enchantment enchantment) Removes an enchantment from the item.skullOwner(String playerName) Sets the skull owner for player head items by name.skullOwner(UUID uuid) Sets the skull owner for player head items by UUID.skullOwner(org.bukkit.OfflinePlayer player) Sets the skull owner for player head items.Makes the item unbreakable.
-
Field Details
-
itemStack
private final org.bukkit.inventory.ItemStack itemStack -
itemMeta
private org.bukkit.inventory.meta.ItemMeta itemMeta
-
-
Constructor Details
-
ItemStackBuilder
public ItemStackBuilder(com.cryptomorin.xseries.XMaterial material) Creates a new ItemStackBuilder from an XMaterial.- Parameters:
material- the XMaterial to use
-
ItemStackBuilder
public ItemStackBuilder(org.bukkit.Material material) Creates a new ItemStackBuilder from a Material.- Parameters:
material- the Material to use
-
ItemStackBuilder
public ItemStackBuilder(org.bukkit.inventory.ItemStack itemStack) Creates a new ItemStackBuilder from an existing ItemStack.- Parameters:
itemStack- the ItemStack to clone
-
-
Method Details
-
of
Creates a new ItemStackBuilder from a material name string. Uses XMaterial for cross-version compatibility.- Parameters:
materialName- the material name- Returns:
- a new ItemStackBuilder, or null if the material is invalid
-
of
Creates a new ItemStackBuilder from an XMaterial.- Parameters:
material- the XMaterial- Returns:
- a new ItemStackBuilder
-
of
Creates a new ItemStackBuilder from a Material.- Parameters:
material- the Material- Returns:
- a new ItemStackBuilder
-
of
Creates a new ItemStackBuilder from an existing ItemStack.- Parameters:
itemStack- the ItemStack to clone- Returns:
- a new ItemStackBuilder
-
name
Sets the display name of the item.- Parameters:
name- the display name (supports color codes with &)- Returns:
- this builder
-
amount
Sets the amount of items in the stack.- Parameters:
amount- the amount- Returns:
- this builder
-
lore
Sets the lore of the item.- Parameters:
lore- the lore lines (supports color codes with &)- Returns:
- this builder
-
lore
Sets the lore of the item.- Parameters:
lore- the lore lines (supports color codes with &)- Returns:
- this builder
-
addLore
Adds lines to the existing lore.- Parameters:
lines- the lines to add- Returns:
- this builder
-
enchant
Adds an enchantment to the item.- Parameters:
enchantment- the enchantmentlevel- the level- Returns:
- this builder
-
enchant
Adds an enchantment using XEnchantment for cross-version compatibility.- Parameters:
enchantment- the XEnchantmentlevel- the level- Returns:
- this builder
-
removeEnchant
Removes an enchantment from the item.- Parameters:
enchantment- the enchantment to remove- Returns:
- this builder
-
glow
Makes the item glow without showing enchantments.- Returns:
- this builder
-
flags
Adds item flags to the item.- Parameters:
flags- the flags to add- Returns:
- this builder
-
hideAttributes
Hides all item attributes.- Returns:
- this builder
-
hideAll
Hides all item flags.- Returns:
- this builder
-
unbreakable
Makes the item unbreakable.- Returns:
- this builder
-
customModelData
Sets the custom model data (1.14+).- Parameters:
data- the custom model data- Returns:
- this builder
-
leatherColor
Sets the color of leather armor.- Parameters:
color- the color- Returns:
- this builder
-
leatherColor
Sets the color of leather armor using RGB.- Parameters:
red- red component (0-255)green- green component (0-255)blue- blue component (0-255)- Returns:
- this builder
-
skullOwner
Sets the skull owner for player head items.- Parameters:
player- the player- Returns:
- this builder
-
skullOwner
Sets the skull owner for player head items by name.- Parameters:
playerName- the player name- Returns:
- this builder
-
skullOwner
Sets the skull owner for player head items by UUID.- Parameters:
uuid- the player's UUID- Returns:
- this builder
-
meta
Applies a custom modifier to the item meta.- Parameters:
modifier- the modifier function- Returns:
- this builder
-
item
Applies a custom modifier to the item stack.- Parameters:
modifier- the modifier function- Returns:
- this builder
-
build
public org.bukkit.inventory.ItemStack build()Builds and returns the ItemStack.- Returns:
- the built ItemStack
-
buildClone
public org.bukkit.inventory.ItemStack buildClone()Builds and returns a clone of the ItemStack.- Returns:
- a clone of the built ItemStack
-