Class AbstractItemBuilder<S>

java.lang.Object
xyz.xenondevs.invui.item.builder.AbstractItemBuilder<S>
Type Parameters:
S - Self reference, used for chaining.
All Implemented Interfaces:
Cloneable, Supplier<@NotNull org.bukkit.inventory.ItemStack>, ItemProvider
Direct Known Subclasses:
BannerBuilder, FireworkBuilder, ItemBuilder, PotionBuilder, SkullBuilder

public abstract class AbstractItemBuilder<S> extends Object implements ItemProvider
Abstract base class for item builders.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The amount of the ItemStack.
    protected org.bukkit.inventory.ItemStack
    The ItemStack to use as a base.
    protected int
    The custom model data value of the ItemStack.
    protected int
    The damage value of the ItemStack
    protected xyz.xenondevs.inventoryaccess.component.ComponentWrapper
    The display name of the ItemStack.
    protected HashMap<org.bukkit.enchantments.Enchantment,Pair<Integer,Boolean>>
    The enchantments of the ItemStack.
    protected List<org.bukkit.inventory.ItemFlag>
    The selected ItemFlags of the ItemStack.
    protected List<xyz.xenondevs.inventoryaccess.component.ComponentWrapper>
    The lore of the ItemStack.
    protected org.bukkit.Material
    The Material of the ItemStack.
    protected List<Function<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack>>
    Additional modifier functions to be run after building the ItemStack.
    protected Boolean
    The unbreakable state of the ItemStack.

    Fields inherited from interface xyz.xenondevs.invui.item.ItemProvider

    EMPTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractItemBuilder(@NotNull org.bukkit.Material material)
    Constructs a new AbstractItemBuilder based on the given Material.
    AbstractItemBuilder(@NotNull org.bukkit.Material material, int amount)
    Constructs a new AbstractItemBuilder based on the given Material and amount.
    AbstractItemBuilder(@NotNull org.bukkit.inventory.ItemStack base)
    Constructs a new AbstractItemBuilder based on the give ItemStack.
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds all existing ItemFlags.
    addEnchantment(org.bukkit.enchantments.Enchantment enchantment, int level, boolean ignoreLevelRestriction)
    Adds an enchantment.
    addItemFlags(@NotNull org.bukkit.inventory.ItemFlag... itemFlags)
    Adds ItemFlags.
    addLegacyLoreLines(@NotNull List<@NotNull String> lines)
    Adds lore lines using the legacy text format.
    addLoreLines(@NotNull String... lines)
    Adds lore lindes using the legacy text format.
    addLoreLines(@NotNull List<@NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper> lines)
    Adds lore lines.
    addLoreLines(@NotNull net.md_5.bungee.api.chat.BaseComponent[]... lines)
    Adds lore lines.
    addLoreLines(@NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper... lines)
    Adds lore lines.
    addModifier(Function<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack> modifier)
    Adds a modifier function, which will be run after building the ItemStack.
    Removes all enchantments.
    Removes all ItemFlags.
    Clears the lore.
    Removes all modifier functions.
    Clones this builder.
    @NotNull org.bukkit.inventory.ItemStack
    get(@Nullable String lang)
    Builds the ItemStack
    int
    Gets the amount.
    @Nullable org.bukkit.inventory.ItemStack
    Gets the base ItemStack of this builder.
    int
    Gets the custom model data value.
    int
    Gets the damage value.
    @Nullable xyz.xenondevs.inventoryaccess.component.ComponentWrapper
    Gets the display name.
    @Nullable HashMap<org.bukkit.enchantments.Enchantment,Pair<Integer,Boolean>>
    Gets the enchantments.
    @Nullable List<org.bukkit.inventory.ItemFlag>
    Gets the configured ItemFlags.
    @Nullable List<xyz.xenondevs.inventoryaccess.component.ComponentWrapper>
    Gets the lore.
    @Nullable org.bukkit.Material
    Gets the Material of this builder.
    @Nullable List<Function<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack>>
    Gets the configured modifier functions.
    @Nullable Boolean
    Gets the unbreakable state, null for default.
    removeEnchantment(org.bukkit.enchantments.Enchantment enchantment)
    Adds an enchantment.
    removeItemFlags(@NotNull org.bukkit.inventory.ItemFlag... itemFlags)
    Removes the specified ItemFlags.
    removeLoreLine(int index)
    Removes a lore line at the given index.
    setAmount(int amount)
    Sets the amount.
    setCustomModelData(int customModelData)
    Sets the custom model data value.
    setDamage(int damage)
    Sets the damage value.
    setDisplayName(String displayName)
    Sets the display name.
    setDisplayName(net.md_5.bungee.api.chat.BaseComponent... displayName)
    Sets the display name.
    setDisplayName(xyz.xenondevs.inventoryaccess.component.ComponentWrapper component)
    Sets the display name.
    setEnchantments(@NotNull HashMap<org.bukkit.enchantments.Enchantment,Pair<Integer,Boolean>> enchantments)
    Sets the enchantments.
    setItemFlags(@NotNull List<org.bukkit.inventory.ItemFlag> itemFlags)
    Sets the ItemFlags.
    setLegacyLore(@NotNull List<@NotNull String> lore)
    Sets the lore using the legacy text format.
    setLore(@NotNull List<@NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper> lore)
    Sets the lore.
    setMaterial(@NotNull org.bukkit.Material material)
    Sets the Material of this builder.
    setUnbreakable(boolean unbreakable)
    Sets the unbreakable state.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface xyz.xenondevs.invui.item.ItemProvider

    get
  • Field Details

    • base

      protected org.bukkit.inventory.ItemStack base
      The ItemStack to use as a base.
    • material

      protected org.bukkit.Material material
      The Material of the ItemStack.
    • amount

      protected int amount
      The amount of the ItemStack.
    • damage

      protected int damage
      The damage value of the ItemStack
    • customModelData

      protected int customModelData
      The custom model data value of the ItemStack.
    • unbreakable

      protected Boolean unbreakable
      The unbreakable state of the ItemStack.
    • displayName

      protected xyz.xenondevs.inventoryaccess.component.ComponentWrapper displayName
      The display name of the ItemStack.
    • lore

      protected List<xyz.xenondevs.inventoryaccess.component.ComponentWrapper> lore
      The lore of the ItemStack.
    • itemFlags

      protected List<org.bukkit.inventory.ItemFlag> itemFlags
      The selected ItemFlags of the ItemStack.
    • enchantments

      protected HashMap<org.bukkit.enchantments.Enchantment,Pair<Integer,Boolean>> enchantments
      The enchantments of the ItemStack.
    • modifiers

      protected List<Function<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack>> modifiers
      Additional modifier functions to be run after building the ItemStack.
  • Constructor Details

    • AbstractItemBuilder

      public AbstractItemBuilder(@NotNull @NotNull org.bukkit.Material material)
      Constructs a new AbstractItemBuilder based on the given Material.
      Parameters:
      material - The Material
    • AbstractItemBuilder

      public AbstractItemBuilder(@NotNull @NotNull org.bukkit.Material material, int amount)
      Constructs a new AbstractItemBuilder based on the given Material and amount.
      Parameters:
      material - The Material
      amount - The amount
    • AbstractItemBuilder

      public AbstractItemBuilder(@NotNull @NotNull org.bukkit.inventory.ItemStack base)
      Constructs a new AbstractItemBuilder based on the give ItemStack. This will keep the ItemStack and uses it's ItemMeta
      Parameters:
      base - The to use as a base
  • Method Details

    • get

      @Contract(value="_ -> new", pure=true) @NotNull public @NotNull org.bukkit.inventory.ItemStack get(@Nullable @Nullable String lang)
      Builds the ItemStack
      Specified by:
      get in interface ItemProvider
      Parameters:
      lang - The language to translate the item in.
      Returns:
      The ItemStack
    • removeLoreLine

      @Contract("_ -> this") @NotNull public S removeLoreLine(int index)
      Removes a lore line at the given index.
      Parameters:
      index - The index of the lore line to remove
      Returns:
      The builder instance
    • clearLore

      @Contract("-> this") @NotNull public S clearLore()
      Clears the lore.
      Returns:
      The builder instance
    • getBase

      @Nullable public @Nullable org.bukkit.inventory.ItemStack getBase()
      Gets the base ItemStack of this builder.
      Returns:
      The base ItemStack
    • getMaterial

      @Nullable public @Nullable org.bukkit.Material getMaterial()
      Gets the Material of this builder.
      Returns:
      The Material
    • setMaterial

      @Contract("_ -> this") @NotNull public S setMaterial(@NotNull @NotNull org.bukkit.Material material)
      Sets the Material of this builder.
      Parameters:
      material - The Material
      Returns:
      The builder instance
    • getAmount

      public int getAmount()
      Gets the amount.
      Returns:
      The amount
    • setAmount

      @Contract("_ -> this") @NotNull public S setAmount(int amount)
      Sets the amount.
      Parameters:
      amount - The amount
      Returns:
      The builder instance
    • getDamage

      public int getDamage()
      Gets the damage value.
      Returns:
      The damage value
    • setDamage

      @Contract("_ -> this") @NotNull public S setDamage(int damage)
      Sets the damage value.
      Parameters:
      damage - The damage value
      Returns:
      The builder instance
    • getCustomModelData

      public int getCustomModelData()
      Gets the custom model data value.
      Returns:
      The custom model data value
    • setCustomModelData

      @Contract("_ -> this") @NotNull public S setCustomModelData(int customModelData)
      Sets the custom model data value.
      Parameters:
      customModelData - The custom model data value
      Returns:
      The builder instance
    • isUnbreakable

      @Nullable public @Nullable Boolean isUnbreakable()
      Gets the unbreakable state, null for default.
      Returns:
      The unbreakable state
    • setUnbreakable

      @Contract("_ -> this") @NotNull public S setUnbreakable(boolean unbreakable)
      Sets the unbreakable state.
      Parameters:
      unbreakable - The unbreakable state
      Returns:
      The builder instance
    • getDisplayName

      @Nullable public @Nullable xyz.xenondevs.inventoryaccess.component.ComponentWrapper getDisplayName()
      Gets the display name.
      Returns:
      The display name
    • setDisplayName

      @Contract("_ -> this") @NotNull public S setDisplayName(String displayName)
      Sets the display name.
      Parameters:
      displayName - The display name
      Returns:
      The builder instance
    • setDisplayName

      @Contract("_ -> this") @NotNull public S setDisplayName(net.md_5.bungee.api.chat.BaseComponent... displayName)
      Sets the display name.
      Parameters:
      displayName - The display name
      Returns:
      The builder instance
    • setDisplayName

      @Contract("_ -> this") @NotNull public S setDisplayName(xyz.xenondevs.inventoryaccess.component.ComponentWrapper component)
      Sets the display name.
      Parameters:
      component - The display name
      Returns:
      The builder instance
    • getLore

      @Nullable public @Nullable List<xyz.xenondevs.inventoryaccess.component.ComponentWrapper> getLore()
      Gets the lore.
      Returns:
      The lore
    • setLore

      @Contract("_ -> this") @NotNull public S setLore(@NotNull @NotNull List<@NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper> lore)
      Sets the lore.
      Parameters:
      lore - The lore
      Returns:
      The builder instance
    • setLegacyLore

      @Contract("_ -> this") @NotNull public S setLegacyLore(@NotNull @NotNull List<@NotNull String> lore)
      Sets the lore using the legacy text format.
      Parameters:
      lore - The lore
      Returns:
      The builder instance
    • addLoreLines

      @Contract("_ -> this") @NotNull public S addLoreLines(@NotNull @NotNull String... lines)
      Adds lore lindes using the legacy text format.
      Parameters:
      lines - The lore lines
      Returns:
      The builder instance
    • addLoreLines

      @Contract("_ -> this") @NotNull public S addLoreLines(@NotNull @NotNull net.md_5.bungee.api.chat.BaseComponent[]... lines)
      Adds lore lines.
      Parameters:
      lines - The lore lines, where each BaseComponent array represents a line.
      Returns:
      The builder instance
    • addLoreLines

      @Contract("_ -> this") @NotNull public S addLoreLines(@NotNull @NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper... lines)
      Adds lore lines.
      Parameters:
      lines - The lore lines
      Returns:
      The builder instance
    • addLoreLines

      @Contract("_ -> this") @NotNull public S addLoreLines(@NotNull @NotNull List<@NotNull xyz.xenondevs.inventoryaccess.component.ComponentWrapper> lines)
      Adds lore lines.
      Parameters:
      lines - The lore lines
      Returns:
      The builder instance
    • addLegacyLoreLines

      @Contract("_ -> this") @NotNull public S addLegacyLoreLines(@NotNull @NotNull List<@NotNull String> lines)
      Adds lore lines using the legacy text format.
      Parameters:
      lines - The lore lines
      Returns:
      The builder instance
    • getItemFlags

      @Nullable public @Nullable List<org.bukkit.inventory.ItemFlag> getItemFlags()
      Gets the configured ItemFlags.
      Returns:
      The ItemFlags
    • setItemFlags

      @Contract("_ -> this") @NotNull public S setItemFlags(@NotNull @NotNull List<org.bukkit.inventory.ItemFlag> itemFlags)
      Sets the ItemFlags.
      Parameters:
      itemFlags - The ItemFlags
      Returns:
      The builder instance
    • addItemFlags

      @Contract("_ -> this") @NotNull public S addItemFlags(@NotNull @NotNull org.bukkit.inventory.ItemFlag... itemFlags)
      Adds ItemFlags.
      Parameters:
      itemFlags - The ItemFlags
      Returns:
      The builder instance
    • addAllItemFlags

      @Contract("-> this") @NotNull public S addAllItemFlags()
      Adds all existing ItemFlags.
      Returns:
      The builder instance
    • removeItemFlags

      @Contract("_ -> this") @NotNull public S removeItemFlags(@NotNull @NotNull org.bukkit.inventory.ItemFlag... itemFlags)
      Removes the specified ItemFlags.
      Parameters:
      itemFlags - The ItemFlags to remove
      Returns:
      The builder instance
    • clearItemFlags

      @Contract("-> this") @NotNull public S clearItemFlags()
      Removes all ItemFlags.
      Returns:
      The builder instance
    • getEnchantments

      @Nullable public @Nullable HashMap<org.bukkit.enchantments.Enchantment,Pair<Integer,Boolean>> getEnchantments()
      Gets the enchantments.
      Returns:
      The enchantments
    • setEnchantments

      @Contract("_ -> this") @NotNull public S setEnchantments(@NotNull @NotNull HashMap<org.bukkit.enchantments.Enchantment,Pair<Integer,Boolean>> enchantments)
      Sets the enchantments.
      Parameters:
      enchantments - The enchantments
      Returns:
      The builder instance
    • addEnchantment

      @Contract("_, _, _ -> this") @NotNull public S addEnchantment(org.bukkit.enchantments.Enchantment enchantment, int level, boolean ignoreLevelRestriction)
      Adds an enchantment.
      Parameters:
      enchantment - The enchantment
      level - The level
      ignoreLevelRestriction - Whether to ignore the level restriction
      Returns:
      The builder instance
    • removeEnchantment

      @Contract("_ -> this") @NotNull public S removeEnchantment(org.bukkit.enchantments.Enchantment enchantment)
      Adds an enchantment.
      Parameters:
      enchantment - The enchantment
      Returns:
      The builder instance
    • clearEnchantments

      @Contract("-> this") @NotNull public S clearEnchantments()
      Removes all enchantments.
      Returns:
      The builder instance
    • getModifiers

      @Nullable public @Nullable List<Function<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack>> getModifiers()
      Gets the configured modifier functions.
      Returns:
      The modifier functions
    • addModifier

      @Contract("_ -> this") @NotNull public S addModifier(Function<org.bukkit.inventory.ItemStack,org.bukkit.inventory.ItemStack> modifier)
      Adds a modifier function, which will be run after building the ItemStack.
      Parameters:
      modifier - The modifier function
      Returns:
      The builder instance
    • clearModifiers

      @Contract("-> this") @NotNull public S clearModifiers()
      Removes all modifier functions.
      Returns:
      The builder instance
    • clone

      @Contract(value="-> new", pure=true) @NotNull public S clone()
      Clones this builder.
      Overrides:
      clone in class Object
      Returns:
      The cloned builder