Class ItemStackBuilder

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

public class ItemStackBuilder extends Object
A fluent builder for creating ItemStacks with various properties.
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.
      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

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

      public static ItemStackBuilder of(com.cryptomorin.xseries.XMaterial material)
      Creates a new ItemStackBuilder from an XMaterial.
      Parameters:
      material - the XMaterial
      Returns:
      a new ItemStackBuilder
    • of

      public static ItemStackBuilder of(org.bukkit.Material material)
      Creates a new ItemStackBuilder from a Material.
      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.
      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.
      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+).
      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.
      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.
      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.
      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