Class ItemBuilder

java.lang.Object
dev.demeng.pluginbase.item.ItemBuilder

public class ItemBuilder extends Object
A utility for quickly creating ItemStacks.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    addLore(@NotNull String line)
    Adds a single line of lore on top of the current lore.
    amount(int amount)
    Changes the amount of the item.
    armorColor(@Nullable org.bukkit.Color color)
    Sets the color of leather armor.
    Clears any enchantments that have been applied.
    Clears all current item flags.
    Clears the item lore.
    @NotNull ItemBuilder
    Clones this item builder.
    static @NotNull ItemBuilder
    create(@Nullable org.bukkit.inventory.ItemStack stack)
    Creates a new builder from an existing item stack.
    static @NotNull ItemBuilder
    create(@Nullable org.bukkit.Material material)
    Creates a new builder from a simple material.
    static @NotNull ItemBuilder
    create(@Nullable org.bukkit.Material material, int amount)
    Creates a new builder from a material and an amount.
    static @NotNull ItemBuilder
    create(@Nullable org.bukkit.Material material, int amount, short damage)
    Creates a new builder from a material, amount, and damage.
    durability(short durability)
    Changes the durability of the item.
    enchant(@NotNull Map<org.bukkit.enchantments.Enchantment,Integer> enchants)
    Adds all the enchants specified in the map, with the key being the enchantment and the value being the level.
    enchant(@NotNull org.bukkit.enchantments.Enchantment enchant, int level)
    Adds a safe enchantment.
    enchant(@NotNull org.bukkit.enchantments.Enchantment enchant, int level, boolean safe)
    Adds an enchantment with customizable safety.
    flags(@NotNull org.bukkit.inventory.ItemFlag... flags)
    Sets the item flags.
    @NotNull org.bukkit.inventory.ItemStack
    get()
    Gets the current item stack.
    static @NotNull org.bukkit.inventory.ItemStack
    getMaterial(@Nullable String strMaterial)
    Gets a material from a string.
    static @NotNull org.bukkit.inventory.ItemStack
    getMaterialOrDef(@Nullable String strMaterial, @NotNull org.bukkit.inventory.ItemStack def)
    Attempts to get a material from a string, but returns the default item stack if the result of the provided material string is invalid or unsupported, instead of throwing an error and just returning stone like getMaterial(String).
    static @NotNull Optional<org.bukkit.inventory.ItemStack>
    getMaterialSafe(@Nullable String strMaterial)
    Gets a material from a string.
    glow(boolean glow)
    Sets if the item should be given a durability enchantment to make it appear glowing and add a hide enchantment item flag.
    lore(@NotNull String... lore)
    Sets the lore to the specified string(s).
    lore(List<String> lore)
    Sets the lore to the specified list.
    modelData(@Nullable Integer modelData)
    Sets the custom model data of the item, which is only supported in 1.14+.
    name(@NotNull String name)
    Sets the display name of the item.
    skullOwner(@NotNull String owner)
    Sets the skull owner of a skull item.
    skullOwner(@NotNull UUID owner)
    Sets the skull owner of a skull item.
    skullTexture(@NotNull String texture)
    Sets the skull texture to the provided base64 encoded string.
    unbreakable(boolean unbreakable)
    Sets if the item should be unbreakable.
    unenchant(@NotNull org.bukkit.enchantments.Enchantment enchant)
    Removes the specified enchantment.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ItemBuilder

      public ItemBuilder()
  • Method Details

    • create

      @NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.inventory.ItemStack stack)
      Creates a new builder from an existing item stack.
      Parameters:
      stack - The item stack to clone, replaced with STONE item stack if null
      Returns:
      The builder
    • create

      @NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.Material material, int amount, short damage)
      Creates a new builder from a material, amount, and damage.
      Parameters:
      material - The material of the stack, replaced with STONE if null
      amount - The amount of the stack
      damage - The damage (a.k.a. the durability) of the stack
      Returns:
      The builder
    • create

      @NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.Material material, int amount)
      Creates a new builder from a material and an amount.
      Parameters:
      material - The material of the stack, replaced with STONE if null
      amount - The amount of the stack
      Returns:
      The builder
    • create

      @NotNull public static @NotNull ItemBuilder create(@Nullable @Nullable org.bukkit.Material material)
      Creates a new builder from a simple material.
      Parameters:
      material - The material of the stack, replaced with STONE if null
      Returns:
      The builder
    • amount

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

      public ItemBuilder durability(short durability)
      Changes the durability of the item.
      Parameters:
      durability - The new durability
      Returns:
      this
    • name

      public ItemBuilder name(@NotNull @NotNull String name)
      Sets the display name of the item.
      Parameters:
      name - The new display name, colorized internally
      Returns:
      this
    • enchant

      public ItemBuilder enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchant, int level, boolean safe)
      Adds an enchantment with customizable safety.
      Parameters:
      enchant - The enchantment to add
      level - The level of the enchantment
      safe - If the enchantment should be safe
      Returns:
      this
    • enchant

      public ItemBuilder enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchant, int level)
      Adds a safe enchantment.
      Parameters:
      enchant - The enchantment to add
      level - The level of the enchantment
      Returns:
      this
    • enchant

      public ItemBuilder enchant(@NotNull @NotNull Map<org.bukkit.enchantments.Enchantment,Integer> enchants)
      Adds all the enchants specified in the map, with the key being the enchantment and the value being the level.
      Parameters:
      enchants - The enchants to add
      Returns:
      this
    • unenchant

      public ItemBuilder unenchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchant)
      Removes the specified enchantment.
      Parameters:
      enchant - The enchantment to remove
      Returns:
      this
    • clearEnchants

      public ItemBuilder clearEnchants()
      Clears any enchantments that have been applied.
      Returns:
      this
    • lore

      public ItemBuilder lore(List<String> lore)
      Sets the lore to the specified list.
      Parameters:
      lore - The lore lines, colorized internally
      Returns:
      this
    • lore

      public ItemBuilder lore(@NotNull @NotNull String... lore)
      Sets the lore to the specified string(s). Each string represents a new line.
      Parameters:
      lore - The lore line(s), colorized internally
      Returns:
      this
    • addLore

      public ItemBuilder addLore(@NotNull @NotNull String line)
      Adds a single line of lore on top of the current lore.
      Parameters:
      line - The lore line to add, colorized internally
      Returns:
      this
    • clearLore

      public ItemBuilder clearLore()
      Clears the item lore.
      Returns:
      this
    • unbreakable

      public ItemBuilder unbreakable(boolean unbreakable)
      Sets if the item should be unbreakable.
      Parameters:
      unbreakable - If the item should be unbreakable
      Returns:
      this
    • flags

      public ItemBuilder flags(@NotNull @NotNull org.bukkit.inventory.ItemFlag... flags)
      Sets the item flags.
      Parameters:
      flags - The flags to set
      Returns:
      this
    • clearFlags

      public ItemBuilder clearFlags()
      Clears all current item flags.
      Returns:
      this
    • glow

      public ItemBuilder glow(boolean glow)
      Sets if the item should be given a durability enchantment to make it appear glowing and add a hide enchantment item flag. Setting this to true will also hide all of your other enchantments in the lore. This should only be enabled for GUI aesthetic purposes.

      Note: When the glow is applied, it should be permanent. It is not recommended that you call this method again to remove the glow since it can effect enchantments and item flags from other sources.

      Parameters:
      glow - If the item should have a glowing effect applied
      Returns:
      this
    • modelData

      public ItemBuilder modelData(@Nullable @Nullable Integer modelData)
      Sets the custom model data of the item, which is only supported in 1.14+. If the server version does not support custom model data, this option is simply ignored.
      Parameters:
      modelData - The custom model data
      Returns:
      this
    • skullOwner

      public ItemBuilder skullOwner(@NotNull @NotNull String owner)
      Sets the skull owner of a skull item. Ignored if the item type is not a player skull.
      Parameters:
      owner - The username of the skull owner
      Returns:
      this
    • skullOwner

      public ItemBuilder skullOwner(@NotNull @NotNull UUID owner)
      Sets the skull owner of a skull item. Ignored if the item type is not a player skull.
      Parameters:
      owner - The UUId of the skull owner
      Returns:
      this
    • skullTexture

      public ItemBuilder skullTexture(@NotNull @NotNull String texture)
      Sets the skull texture to the provided base64 encoded string. Ignored if the item type is not a player skull.
      Parameters:
      texture - The base64 encoded texture
      Returns:
      this
    • armorColor

      public ItemBuilder armorColor(@Nullable @Nullable org.bukkit.Color color)
      Sets the color of leather armor. Ignored if the item type is not leather armor.
      Parameters:
      color - The color to change the armor to
      Returns:
      this
    • get

      @NotNull public @NotNull org.bukkit.inventory.ItemStack get()
      Gets the current item stack.
      Returns:
      The current item stack
    • copy

      @NotNull public @NotNull ItemBuilder copy()
      Clones this item builder.
      Returns:
      The cloned instance
    • getMaterialSafe

      @NotNull public static @NotNull Optional<org.bukkit.inventory.ItemStack> getMaterialSafe(@Nullable @Nullable String strMaterial)
      Gets a material from a string. Note that this actually returns an item stack as a data values may need to be included on legacy versions.
      Parameters:
      strMaterial - The string material to parse
      Returns:
      A standard item stack with no meta, or null if the material is invalid or unsupported
    • getMaterial

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack getMaterial(@Nullable @Nullable String strMaterial)
      Gets a material from a string. Throws an error if the material is invalid or unsupported, unlike getMaterialSafe(String).
      Parameters:
      strMaterial - The string material to parse
      Returns:
      A standard item stack with no meta, or stone if invalid/unsupported
      See Also:
    • getMaterialOrDef

      @NotNull public static @NotNull org.bukkit.inventory.ItemStack getMaterialOrDef(@Nullable @Nullable String strMaterial, @NotNull @NotNull org.bukkit.inventory.ItemStack def)
      Attempts to get a material from a string, but returns the default item stack if the result of the provided material string is invalid or unsupported, instead of throwing an error and just returning stone like getMaterial(String).
      Parameters:
      strMaterial - The string material to parse
      def - The default material if the provided material is invalid or unsupported
      Returns:
      A standard item stack with no meta, or the default stack if invalid/unsupported
      See Also: