java.lang.Object
tech.guilhermekaua.spigotboot.core.spigot.utils.ItemBuilder

public class ItemBuilder extends Object
A utility class that helps to create and modify ItemStacks.
  • Constructor Details

    • ItemBuilder

      public ItemBuilder(org.bukkit.inventory.ItemStack item)
      Creates a new ItemBuilder with the given ItemStack.
      Parameters:
      item - the ItemStack to use
    • ItemBuilder

      public ItemBuilder(org.bukkit.Material type)
      Creates a new ItemBuilder with the given Material type.
      Parameters:
      type - the Material type to use
    • ItemBuilder

      public ItemBuilder(org.bukkit.Material type, int data)
      Creates a new ItemBuilder with the given Material type and data value.
      Parameters:
      type - the Material type to use
      data - the data value to use
    • ItemBuilder

      public ItemBuilder(org.bukkit.Material type, org.bukkit.Color color)
      Creates a new ItemBuilder with a leather armor item of the given color.
      Parameters:
      type - the Material type to use
      color - the Color to use
  • Method Details

    • setItem

      public ItemBuilder setItem(org.bukkit.inventory.ItemStack item)
    • headUrl

      public ItemBuilder headUrl(String url)
      Replaces the current item with a player head skinned from a Mojang texture URL. Works version-proof from 1.8.8 to the latest release (see HeadUtils.getHeadByUrl(String)); a null, blank, or malformed URL yields a bare head rather than throwing.
      Parameters:
      url - the Mojang texture URL (e.g. http://textures.minecraft.net/texture/<hash>)
      Returns:
      this ItemBuilder instance for chaining
    • headName

      public ItemBuilder headName(String name)
      Replaces the current item with a player head owned by the named player.
      Parameters:
      name - the player name whose skin to use
      Returns:
      this ItemBuilder instance for chaining
    • headUUID

      public ItemBuilder headUUID(UUID uuid)
      Replaces the current item with a player head owned by the player with the given UUID.
      Parameters:
      uuid - the player UUID whose skin to use
      Returns:
      this ItemBuilder instance for chaining
    • headUUID

      public ItemBuilder headUUID(String uuid)
      Replaces the current item with a player head owned by the player with the given UUID string. A null or unparseable UUID yields a bare head rather than throwing.
      Parameters:
      uuid - the player UUID in canonical string form
      Returns:
      this ItemBuilder instance for chaining
    • setGlow

      public ItemBuilder setGlow(boolean glow)
    • changeItemMeta

      public ItemBuilder changeItemMeta(Consumer<org.bukkit.inventory.meta.ItemMeta> consumer)
      Changes the ItemMeta of the ItemStack using the given Consumer function.
      Parameters:
      consumer - the Consumer function to apply to the ItemMeta
      Returns:
      this ItemBuilder instance for chaining
    • setName

      public ItemBuilder setName(String name)
      Sets the display name of the ItemStack.
      Parameters:
      name - the display name to use
      Returns:
      this ItemBuilder instance for chaining
    • addLore

      public ItemBuilder addLore(String... lore)
      Adds some strings to the lore of the ItemStack.
      Parameters:
      lore - an array of strings to add to the lore
      Returns:
      this ItemBuilder instance for chaining
    • addLore

      public ItemBuilder addLore(int index, String lore)
      Adds a string to the lore of the ItemStack at the given index.
      Parameters:
      index - the index to insert the string at
      lore - the string to add to the lore
      Returns:
      this ItemBuilder instance for chaining
    • setLore

      public ItemBuilder setLore(int index, String lore)
      Replaces a string in the lore of the ItemStack at the given index.
      Parameters:
      index - the index to replace the string at
      lore - the string to replace in the lore
      Returns:
      this ItemBuilder instance for chaining
    • deleteLoreLine

      public ItemBuilder deleteLoreLine(int index)
      Deletes a string from the lore of the ItemStack at the given index.
      Parameters:
      index - the index to delete the string from
      Returns:
      this ItemBuilder instance for chaining
    • findLore

      public int findLore(String lore)
      Finds the index of a string in the lore of the ItemStack that contains the given substring.
      Parameters:
      lore - the substring to look for in the lore
      Returns:
      the index of the string that contains the substring, or -1 if not found
    • getLore

      public List<String> getLore()
      Returns the lore of the ItemStack as a list of strings.
      Returns:
      the lore of the ItemStack, or null if none
    • setLore

      public ItemBuilder setLore(String... lore)
      Sets the lore of the ItemStack.
      Parameters:
      lore - an array of strings to use as the lore
      Returns:
      this ItemBuilder instance for chaining
    • setLore

      public ItemBuilder setLore(List<String> lore)
      Sets the lore of the ItemStack.
      Parameters:
      lore - a list of strings to use as the lore
      Returns:
      this ItemBuilder instance for chaining
    • placeholder

      public ItemBuilder placeholder(String placeholder, String value)
      Replaces a placeholder in the lore of the ItemStack with a given value.
      Parameters:
      placeholder - the placeholder to replace
      value - the value to replace with
      Returns:
      this ItemBuilder instance for chaining
    • setAmount

      public ItemBuilder setAmount(int amount)
      Sets the stack size, clamped to at least 1.
      Parameters:
      amount - the desired amount
      Returns:
      this ItemBuilder instance for chaining
    • setLegacyModelData

      public ItemBuilder setLegacyModelData(Integer data)
      Sets the legacy durability/data value used by old pre-flattening item variants.
      Parameters:
      data - the legacy data value, or null to leave it unchanged
      Returns:
      this ItemBuilder instance for chaining
    • setCustomModelData

      public ItemBuilder setCustomModelData(Integer data)
      Sets the custom model data. This uses the component-backed custom model data float list when available on newer servers, falls back to the 1.14+ integer API, and is a no-op on older servers or when data is null.
      Parameters:
      data - the custom model data, or null to leave it unset
      Returns:
      this ItemBuilder instance for chaining
    • setCustomModelDataComponent

      public ItemBuilder setCustomModelDataComponent(List<Float> floats, List<Boolean> flags, List<String> strings, List<org.bukkit.Color> colors)
      Sets custom model data component values on servers that expose that API. Null lists are left unchanged on the component snapshot.
      Parameters:
      floats - range dispatch float values, or null to leave unchanged
      flags - condition flag values, or null to leave unchanged
      strings - select string values, or null to leave unchanged
      colors - tint colors, or null to leave unchanged
      Returns:
      this ItemBuilder instance for chaining
    • setCustomModelDataFloats

      public ItemBuilder setCustomModelDataFloats(Float... floats)
      Sets custom model data component float values.
      Parameters:
      floats - range dispatch float values
      Returns:
      this ItemBuilder instance for chaining
    • setCustomModelDataFlags

      public ItemBuilder setCustomModelDataFlags(Boolean... flags)
      Sets custom model data component boolean flag values.
      Parameters:
      flags - condition flag values
      Returns:
      this ItemBuilder instance for chaining
    • setCustomModelDataStrings

      public ItemBuilder setCustomModelDataStrings(String... strings)
      Sets custom model data component string values.
      Parameters:
      strings - select string values
      Returns:
      this ItemBuilder instance for chaining
    • setCustomModelDataColors

      public ItemBuilder setCustomModelDataColors(org.bukkit.Color... colors)
      Sets custom model data component tint colors.
      Parameters:
      colors - tint colors
      Returns:
      this ItemBuilder instance for chaining
    • setItemModel

      public ItemBuilder setItemModel(String itemModel)
      Sets the direct item model key on servers that expose that API.
      Parameters:
      itemModel - a namespaced key such as my_pack:bronze_sword
      Returns:
      this ItemBuilder instance for chaining
    • ofMaterial

      public static ItemBuilder ofMaterial(String... candidates)
      Resolves the first Material that matches one of the given config names (modern name first, legacy fallback via TypeUtil.getMaterialFromLegacy(String)), falling back to Material.STONE when none resolve — so a GUI never fails to render an item.
      Parameters:
      candidates - material names to try in order
      Returns:
      a builder for the resolved material, or STONE
    • ofHead

      public static ItemBuilder ofHead(String textureUrlOrName)
      Creates an ItemBuilder wrapping a player head resolved from either a Mojang texture URL or a player name. When textureUrlOrName matches HeadUtils.isTextureUrl(String), the head is skinned via HeadUtils.getHeadByUrl(String); otherwise HeadUtils.getHeadByName(String) is used. A null or blank value yields a bare head rather than throwing.
      Parameters:
      textureUrlOrName - a Mojang texture URL or player name
      Returns:
      a builder wrapping the resolved player head
    • setMaterial

      public ItemBuilder setMaterial(String... candidates)
    • setRawName

      public ItemBuilder setRawName(String name)
      Sets the display name verbatim, without colour translation — for names that are already formatted (e.g. by ChatMarkup.legacy(...)).
      Parameters:
      name - the pre-formatted display name
      Returns:
      this ItemBuilder instance for chaining
    • setRawLore

      public ItemBuilder setRawLore(List<String> lore)
      Sets the lore verbatim, without colour translation — for lines that are already formatted.
      Parameters:
      lore - the pre-formatted lore lines
      Returns:
      this ItemBuilder instance for chaining
    • setRawLore

      public ItemBuilder setRawLore(String... lore)
      Sets the lore verbatim, without colour translation — for lines that are already formatted.
      Parameters:
      lore - the pre-formatted lore lines
      Returns:
      this ItemBuilder instance for chaining
    • wrap

      public org.bukkit.inventory.ItemStack wrap()
      Returns the ItemStack that this builder is working on.
      Returns:
      the ItemStack instance