Package com.ultikits.ultitools.utils
Class ItemStackBuilder
java.lang.Object
com.ultikits.ultitools.utils.ItemStackBuilder
A fluent builder for creating ItemStacks with various properties.
用于创建具有各种属性的 ItemStack 的流式构建器。
- 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.从 XMaterial 创建新的 ItemStackBuilder。
- Parameters:
material- the XMaterial to use
-
ItemStackBuilder
public ItemStackBuilder(org.bukkit.Material material) Creates a new ItemStackBuilder from a Material.从 Material 创建新的 ItemStackBuilder。
- Parameters:
material- the Material to use
-
ItemStackBuilder
public ItemStackBuilder(org.bukkit.inventory.ItemStack itemStack) Creates a new ItemStackBuilder from an existing ItemStack.从现有的 ItemStack 创建新的 ItemStackBuilder。
- Parameters:
itemStack- the ItemStack to clone
-
-
Method Details
-
of
Creates a new ItemStackBuilder from a material name string. Uses XMaterial for cross-version compatibility.从材料名称字符串创建新的 ItemStackBuilder。 使用 XMaterial 实现跨版本兼容。
- Parameters:
materialName- the material name- Returns:
- a new ItemStackBuilder, or null if the material is invalid
-
of
Creates a new ItemStackBuilder from an XMaterial.从 XMaterial 创建新的 ItemStackBuilder。
- Parameters:
material- the XMaterial- Returns:
- a new ItemStackBuilder
-
of
Creates a new ItemStackBuilder from a Material.从 Material 创建新的 ItemStackBuilder。
- Parameters:
material- the Material- Returns:
- a new ItemStackBuilder
-
of
Creates a new ItemStackBuilder from an existing ItemStack.从现有 ItemStack 创建新的 ItemStackBuilder。
- 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.使用 XEnchantment 添加附魔以实现跨版本兼容。
- 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+).设置自定义模型数据(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.使用 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.通过 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.构建并返回 ItemStack。
- Returns:
- the built ItemStack
-
buildClone
public org.bukkit.inventory.ItemStack buildClone()Builds and returns a clone of the ItemStack.构建并返回 ItemStack 的副本。
- Returns:
- a clone of the built ItemStack
-