Interface ItemBuilder


public interface ItemBuilder
Fast builder for ItemStacks.
  • Method Details

    • name

      ItemBuilder name(String name)
      Changes the display name of the item.
      Parameters:
      name - The new name
      Returns:
      this builder
    • emptyName

      ItemBuilder emptyName()
      Sets an empty display name for the item.
      Returns:
      this builder
    • name

      String name()
      Gets the current name of the item.
      Returns:
      the name
    • hasName

      boolean hasName()
      Checks whether the item has a custom display name.
      Returns:
      true if it has a display name, otherwise false
    • amount

      ItemBuilder amount(int amount)
      Changes the amount of the item.
      Parameters:
      amount - The new amount
      Returns:
      this builder
    • amount

      int amount()
      Gets the current amount of the item.
      Returns:
      the amount
    • lore

      ItemBuilder lore(String... lore)
      Changes the lore of the item.
      Parameters:
      lore - The new lore
      Returns:
      this builder
    • lore

      ItemBuilder lore(List<String> lore)
      Changes the lore of the item.
      Parameters:
      lore - The new lore
      Returns:
      this builder
    • addLore

      ItemBuilder addLore(String line)
      Adds a line to the lore.
      Parameters:
      line - The line to add
      Returns:
      this builder
    • addLoreNLable

      ItemBuilder addLoreNLable(String line)
      Adds a line to the lore, splitting it into multiple lines at new line characters.
      Parameters:
      line - The line(s) to add
      Returns:
      this builder
    • addLore

      ItemBuilder addLore(String... loreLines)
      Adds multiple lines to the lore.
      Parameters:
      loreLines - The lines to add
      Returns:
      this builder
    • addLore

      ItemBuilder addLore(List<String> loreLines)
      Adds multiple lines to the lore.
      Parameters:
      loreLines - The lines to add
      Returns:
      this builder
    • addLoreNLable

      ItemBuilder addLoreNLable(List<String> loreLines)
      Adds multiple lines to the lore, splitting each at new line characters.
      Parameters:
      loreLines - The lines to add
      Returns:
      this builder
    • addEmptyLore

      ItemBuilder addEmptyLore()
      Adds an empty line to the lore.
      Returns:
      this builder
    • replaceLore

      ItemBuilder replaceLore(int line, String replacement)
      Attempts to replace a line in the lore.

      Nothing happens if line is less than 0, or greater than/equal to loreLines().

      Parameters:
      line - The line / entry to replace, starting at 0
      replacement - The new value of the line
      Returns:
      this builder
    • computeLoreComponents

      ItemBuilder computeLoreComponents(UnaryOperator<String> lineOperator)
      Computes all lore lines using the given operator.

      Depending on the server variant used, the operator might get called for each line straight or only the contents of text components for each component in every line.

      Parameters:
      lineOperator - The operator for each text component or line
      Returns:
      this builder
    • clearLore

      ItemBuilder clearLore()
      Clears the lore of the item.
      Returns:
      this builder
    • hasLore

      boolean hasLore()
      Get whether this item has any lore line.
      Returns:
      true if it has lore, otherwise false
    • loreLines

      int loreLines()
      Get the amount of lines the lore has.
      Returns:
      Amount of lines / entries in the lore
    • friendlyDescription

      ItemBuilder friendlyDescription(String description, ChatColor lineColor)
      Sets the name and lore of the item with auto-wrapping.

      The description is split into multiple lines at new line characters and wrapped at 40 - 50 characters, if necessary.

      Each line is colored with the given line color. The first line is being set as the display name of the item (name(String)) and the rest as lore lines (lore(List)).

      Parameters:
      description - The description to set as name and lore
      lineColor - The color for each line
      Returns:
      this builder
    • addEnchant

      ItemBuilder addEnchant(Enchantment ench, int lvl, boolean ignoreLevelRestriction)
      Adds the given enchantment to the item.
      Parameters:
      ench - The enchantment
      lvl - The level
      ignoreLevelRestriction - Whether to ignore level restrictions
      Returns:
      this builder
    • enchantLevel

      int enchantLevel(Enchantment ench)
      Get the level of the given enchantment on the item.
      Parameters:
      ench - The enchantment
      Returns:
      the level, or 0 if the item does not have the enchantment
    • dye

      ItemBuilder dye(DyeColor color)
      Dyes the item with the given color.

      Only works for dyeable items (like leather armor, wool, etc.).

      Parameters:
      color - The dye color
      Returns:
      this builder
    • dye

      ItemBuilder dye(Team team)
      Dyes the item with the given team's color.

      Only works for dyeable items (like leather armor, wool, etc.). Uses Team.getDyeColor().

      Parameters:
      team - The team
      Returns:
      this builder
    • hideAttributes

      ItemBuilder hideAttributes()
      Hides all attributes of the item (like attack damage, armor, etc.).
      Returns:
      this builder
    • glowing

      ItemBuilder glowing()
      Makes the item glowing like it has an enchantment.
      Returns:
      this builder
      See Also:
    • unbreakable

      ItemBuilder unbreakable()
      Makes the item unbreakable.
      Returns:
      this builder
      See Also:
    • maxStackLimit

      ItemBuilder maxStackLimit()
      Sets a maximum stack amount possible for the item (1.20.5+ only).
      Returns:
      this builder
    • cloned

      ItemBuilder cloned()
      Clones the item used by this builder.
      Returns:
      this builder
    • build

      ItemStack build()
      Builds the item.

      Might be the same instance as the one passed to the builder, depending on whether cloned() was called.

      Returns:
      the built item
    • getInternalMeta

      @Nullable @Nullable ItemMeta getInternalMeta()
      Gets the internal item meta used by this builder.
      Returns:
      the item meta, may be null if the item has no meta at all (air)
    • isMetaless

      boolean isMetaless()
      Checks whether the item is metaless (like air).
      Returns:
      true if metaless, otherwise false
    • of

      static ItemBuilder of(ItemStack item)
      Creates a new item builder for the given item.

      Modifies the given item instance unless cloned() is called.

      Parameters:
      item - The item
      Returns:
      the item builder
    • of

      static ItemBuilder of(Material mat)
      Creates a new item builder for the given material.
      Parameters:
      mat - The material
      Returns:
      the item builder
    • of

      static ItemBuilder of(Material mat, int amount)
      Creates a new item builder for the given material and amount.
      Parameters:
      mat - The material
      amount - The amount
      Returns:
      the item builder