Class ItemStackBuilder

java.lang.Object
space.maxus.flare.item.ItemStackBuilder
All Implemented Interfaces:
ItemProvider

public class ItemStackBuilder extends Object implements ItemProvider
An ItemStack Builder, which is a wrapper around an ItemStack that contains multiple convenience methods for constructing ItemStacks.
  • Constructor Details

    • ItemStackBuilder

      public ItemStackBuilder(org.bukkit.Material material, @Nullable @Nullable org.bukkit.entity.Player player)
      Constructs a new ItemStackBuilder for the given Material.
      Parameters:
      material - Material of the Item
      player - Used for PlaceholderAPI resolution. May be null.
  • Method Details

    • type

      public ItemStackBuilder type(org.bukkit.Material type)
      Changes item type without fully wiping its meta
      Parameters:
      type - New item type
      Returns:
      This builder
    • count

      public ItemStackBuilder count(@org.checkerframework.common.value.qual.IntRange(from=0L, to=128L) int count)
      Sets the amount of items in this stack
      Parameters:
      count - New item count. Must be within 0 to 128, otherwise Bukkit errors may arise
      Returns:
      This builder
    • editMeta

      public ItemStackBuilder editMeta(Consumer<org.bukkit.inventory.meta.ItemMeta> meta)
      Edits meta of this item
      Parameters:
      meta - Consumer that edits meta of the item
      Returns:
      This builder
    • editTypedMeta

      public <M extends org.bukkit.inventory.meta.ItemMeta> ItemStackBuilder editTypedMeta(Consumer<M> meta)
      Edits meta of this item, using a generic type ItemStackBuilder
      Type Parameters:
      M - The type of meta.
      Parameters:
      meta - Consumer that edits meta of the item
      Returns:
      This builder
    • hideAllFlags

      public ItemStackBuilder hideAllFlags()
      Adds all ItemFlags to this item, essentially hiding all extra data from lore.
      Returns:
      This builder
    • hideFlags

      public ItemStackBuilder hideFlags(org.bukkit.inventory.ItemFlag... flags)
      Adds certain provided item flags to this item
      Parameters:
      flags - Flags to be added
      Returns:
      This builder
    • lore

      public ItemStackBuilder lore(@NotNull @NotNull String lore)
      Sets lore of the item to the provided lore via Items.loreMeta(java.lang.String)
      Parameters:
      lore - Lore to be set
      Returns:
      This builder
    • lore

      public ItemStackBuilder lore(@NotNull @NotNull List<net.kyori.adventure.text.Component> lore)
      Sets this item's lore to provided component list
      Parameters:
      lore - Lore to be set
      Returns:
      This builder
    • addLore

      public ItemStackBuilder addLore(@NotNull @NotNull String lore)
      Adds provided lore to this item's lore via FlareUtil.partitionString(String)
      Parameters:
      lore - Lore to be added to this item
      Returns:
      This builder
    • addLore

      public ItemStackBuilder addLore(@NotNull @NotNull List<net.kyori.adventure.text.Component> lore)
      Adds all components to this item lore
      Parameters:
      lore - Lore to be added to this item
      Returns:
      This builder
    • addLoreLine

      public ItemStackBuilder addLoreLine(@NotNull @NotNull String line)
      Adds a single lore line to this item lore
      Parameters:
      line - Lore line to be added
      Returns:
      This builder
    • addLoreLine

      public ItemStackBuilder addLoreLine(@NotNull @NotNull net.kyori.adventure.text.Component line)
      Adds a single lore line to this item lore
      Parameters:
      line - Lore line to be added
      Returns:
      This builder
    • padLore

      public ItemStackBuilder padLore()
      Adds an empty line to this lore
      Returns:
      This builder
    • name

      public ItemStackBuilder name(@NotNull @NotNull String name)
      Sets this item name to provided name
      Parameters:
      name - Name to be set
      Returns:
      This builder
    • glint

      public ItemStackBuilder glint()
      Adds enchantment glint to this item.
      You might want to call hideAllFlags() or hideFlags(ItemFlag...) after this to hide enchantment info
      Returns:
      This builder
    • headSkin

      public ItemStackBuilder headSkin(@Nullable @Nullable String skin)
      Sets this item's head skin to the provided skin. Will fail if the item is not of type Material.PLAYER_HEAD
      Parameters:
      skin - Base64 data of head skin. See Items.head(String) for more info
      Returns:
      This builder
    • branch

      public ItemStackBuilder branch(boolean condition, Consumer<ItemStackBuilder> ifTrue, Consumer<ItemStackBuilder> ifFalse)
      A utility method that branches configuration of this builder based on condition.
      Parameters:
      condition - Condition to be checked
      ifTrue - Executed if condition is true
      ifFalse - Executed if condition is false
      Returns:
      This builder
    • branch

      public ItemStackBuilder branch(boolean condition, Consumer<ItemStackBuilder> ifTrue)
      A utility method that branches configuration of this builder based on condition.
      Parameters:
      condition - Condition to be checked
      ifTrue - Executed if condition is true
      Returns:
      This builder
    • build

      public org.bukkit.inventory.ItemStack build()
      Finishes this builder and returns clone of inner stack
      Returns:
      Clone of inner stack
    • provide

      public org.bukkit.inventory.ItemStack provide()
      Description copied from interface: ItemProvider
      Provides an item stack.
      Specified by:
      provide in interface ItemProvider
      Returns:
      an ItemStack. May be null