Class ItemStackBuilder

java.lang.Object
com.ultikits.ultitools.utils.ItemStackBuilder

public class ItemStackBuilder extends Object
A fluent builder for creating ItemStacks with various properties.

用于创建具有各种属性的 ItemStack 的流式构建器。

Since:
6.2.0
Version:
1.0.0
Author:
wisdomme
  • 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

      @Nullable public static ItemStackBuilder of(String materialName)
      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

      public static ItemStackBuilder of(com.cryptomorin.xseries.XMaterial material)
      Creates a new ItemStackBuilder from an XMaterial.

      从 XMaterial 创建新的 ItemStackBuilder。

      Parameters:
      material - the XMaterial
      Returns:
      a new ItemStackBuilder
    • of

      public static ItemStackBuilder of(org.bukkit.Material material)
      Creates a new ItemStackBuilder from a Material.

      从 Material 创建新的 ItemStackBuilder。

      Parameters:
      material - the Material
      Returns:
      a new ItemStackBuilder
    • of

      public static ItemStackBuilder of(org.bukkit.inventory.ItemStack itemStack)
      Creates a new ItemStackBuilder from an existing ItemStack.

      从现有 ItemStack 创建新的 ItemStackBuilder。

      Parameters:
      itemStack - the ItemStack to clone
      Returns:
      a new ItemStackBuilder
    • name

      public ItemStackBuilder name(String name)
      Sets the display name of the item.

      设置物品的显示名称。

      Parameters:
      name - the display name (supports color codes with &)
      Returns:
      this builder
    • amount

      public ItemStackBuilder amount(int amount)
      Sets the amount of items in the stack.

      设置堆叠中的物品数量。

      Parameters:
      amount - the amount
      Returns:
      this builder
    • lore

      public ItemStackBuilder lore(String... lore)
      Sets the lore of the item.

      设置物品的描述。

      Parameters:
      lore - the lore lines (supports color codes with &)
      Returns:
      this builder
    • lore

      public ItemStackBuilder lore(List<String> lore)
      Sets the lore of the item.

      设置物品的描述。

      Parameters:
      lore - the lore lines (supports color codes with &)
      Returns:
      this builder
    • addLore

      public ItemStackBuilder addLore(String... lines)
      Adds lines to the existing lore.

      向现有描述添加行。

      Parameters:
      lines - the lines to add
      Returns:
      this builder
    • enchant

      public ItemStackBuilder enchant(org.bukkit.enchantments.Enchantment enchantment, int level)
      Adds an enchantment to the item.

      为物品添加附魔。

      Parameters:
      enchantment - the enchantment
      level - the level
      Returns:
      this builder
    • enchant

      public ItemStackBuilder enchant(com.cryptomorin.xseries.XEnchantment enchantment, int level)
      Adds an enchantment using XEnchantment for cross-version compatibility.

      使用 XEnchantment 添加附魔以实现跨版本兼容。

      Parameters:
      enchantment - the XEnchantment
      level - the level
      Returns:
      this builder
    • removeEnchant

      public ItemStackBuilder removeEnchant(org.bukkit.enchantments.Enchantment enchantment)
      Removes an enchantment from the item.

      从物品移除附魔。

      Parameters:
      enchantment - the enchantment to remove
      Returns:
      this builder
    • glow

      public ItemStackBuilder glow()
      Makes the item glow without showing enchantments.

      使物品发光但不显示附魔。

      Returns:
      this builder
    • flags

      public ItemStackBuilder flags(org.bukkit.inventory.ItemFlag... flags)
      Adds item flags to the item.

      为物品添加物品标志。

      Parameters:
      flags - the flags to add
      Returns:
      this builder
    • hideAttributes

      public ItemStackBuilder hideAttributes()
      Hides all item attributes.

      隐藏所有物品属性。

      Returns:
      this builder
    • hideAll

      public ItemStackBuilder hideAll()
      Hides all item flags.

      隐藏所有物品标志。

      Returns:
      this builder
    • unbreakable

      public ItemStackBuilder unbreakable()
      Makes the item unbreakable.

      使物品不可破坏。

      Returns:
      this builder
    • customModelData

      public ItemStackBuilder customModelData(int data)
      Sets the custom model data (1.14+).

      设置自定义模型数据(1.14+)。

      Parameters:
      data - the custom model data
      Returns:
      this builder
    • leatherColor

      public ItemStackBuilder leatherColor(org.bukkit.Color color)
      Sets the color of leather armor.

      设置皮革护甲的颜色。

      Parameters:
      color - the color
      Returns:
      this builder
    • leatherColor

      public ItemStackBuilder leatherColor(int red, int green, int blue)
      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

      public ItemStackBuilder skullOwner(org.bukkit.OfflinePlayer player)
      Sets the skull owner for player head items.

      设置玩家头颅的所有者。

      Parameters:
      player - the player
      Returns:
      this builder
    • skullOwner

      public ItemStackBuilder skullOwner(String playerName)
      Sets the skull owner for player head items by name.

      通过名称设置玩家头颅的所有者。

      Parameters:
      playerName - the player name
      Returns:
      this builder
    • skullOwner

      public ItemStackBuilder skullOwner(UUID uuid)
      Sets the skull owner for player head items by UUID.

      通过 UUID 设置玩家头颅的所有者。

      Parameters:
      uuid - the player's UUID
      Returns:
      this builder
    • meta

      public ItemStackBuilder meta(Consumer<org.bukkit.inventory.meta.ItemMeta> modifier)
      Applies a custom modifier to the item meta.

      对物品元数据应用自定义修改器。

      Parameters:
      modifier - the modifier function
      Returns:
      this builder
    • item

      public ItemStackBuilder item(Consumer<org.bukkit.inventory.ItemStack> modifier)
      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