Class BaseItemBuilder<B extends BaseItemBuilder<B>>

java.lang.Object
io.rhythmknights.coreapi.modal.builder.item.BaseItemBuilder<B>
Type Parameters:
B - The ItemBuilder type so the methods can cast to the subtype
Direct Known Subclasses:
BannerBuilder, BookBuilder, FireworkBuilder, ItemBuilder, MapBuilder, SkullBuilder

public abstract class BaseItemBuilder<B extends BaseItemBuilder<B>> extends Object
Contains all the common methods for the future ItemBuilders This class expects Components to be pre-parsed by CoreFramework's TextUtility. CoreAPI handles ONLY GUI building - no text parsing.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BaseItemBuilder(@NotNull org.bukkit.inventory.ItemStack itemStack)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    amount(int amount)
    Sets the amount of items
    @NotNull ModalItem
    Creates a ModalItem instead of an ItemStack
    @NotNull ModalItem
    asModalItem(@NotNull ModalAction<org.bukkit.event.inventory.InventoryClickEvent> action)
    Creates a ModalItem instead of an ItemStack
    @NotNull org.bukkit.inventory.ItemStack
    Builds the item into ItemStack
    color(@NotNull org.bukkit.Color color)
    Color an ItemStack
    protected @NotNull net.kyori.adventure.text.Component
    Deserializes the object with the right ComponentSerializer for the current MC version
    disenchant(@NotNull org.bukkit.enchantments.Enchantment enchantment)
    Disenchants a certain Enchantment from the ItemStack
    enchant(@NotNull Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)
    Enchants the ItemStack with the specified map where the value is the level of the key's enchantment
    enchant(@NotNull Map<org.bukkit.enchantments.Enchantment,Integer> enchantments, boolean ignoreLevelRestriction)
    Enchants the ItemStack with the specified map where the value is the level of the key's enchantment
    enchant(@NotNull org.bukkit.enchantments.Enchantment enchantment)
    Enchants the ItemStack
    enchant(@NotNull org.bukkit.enchantments.Enchantment enchantment, int level)
    Enchants the ItemStack
    enchant(@NotNull org.bukkit.enchantments.Enchantment enchantment, int level, boolean ignoreLevelRestriction)
    Enchants the ItemStack
    flags(@NotNull org.bukkit.inventory.ItemFlag... flags)
    Add an ItemFlag to the item
    protected @NotNull org.bukkit.inventory.ItemStack
    Package private getter for extended builders
    protected @NotNull org.bukkit.inventory.meta.ItemMeta
    Package private getter for extended builders
    Makes the ItemStack glow
    glow(boolean glow)
    Adds or removes the ItemStack glow
    lore(@NotNull List<@Nullable net.kyori.adventure.text.Component> lore)
    Set the lore lines of an item Components should be pre-parsed by CoreFramework's TextUtility
    lore(@NotNull Consumer<List<@Nullable net.kyori.adventure.text.Component>> lore)
    Consumer for freely adding to the lore Components should be pre-parsed by CoreFramework's TextUtility
    lore(@Nullable net.kyori.adventure.text.Component @NotNull ... lore)
    Set the lore lines of an item Components should be pre-parsed by CoreFramework's TextUtility
    model(int modelData)
    Sets the custom model data of the item Added in 1.13
    name(@NotNull net.kyori.adventure.text.Component name)
    Sets the display name of the item using Component Component should be pre-parsed by CoreFramework's TextUtility
    pdc(@NotNull Consumer<org.bukkit.persistence.PersistentDataContainer> consumer)
    Consumer for applying PersistentDataContainer to the item This method will only work on versions above 1.14
    removeNBT(@NotNull String key)
    Removes NBT tag from the ItemStack
    protected @NotNull Object
    serializeComponent(@NotNull net.kyori.adventure.text.Component component)
    Serializes the component with the right ComponentSerializer for the current MC version Expects Components to be pre-parsed by CoreFramework's TextUtility
    protected void
    setItemStack(@NotNull org.bukkit.inventory.ItemStack itemStack)
    Package private setter for the extended builders
    protected void
    setMeta(@NotNull org.bukkit.inventory.meta.ItemMeta meta)
    Package private setter for the extended builders
    setNBT(@NotNull String key, boolean value)
    Sets NBT tag to the ItemStack
    setNBT(@NotNull String key, @NotNull String value)
    Sets NBT tag to the ItemStack
    Makes the ItemStack unbreakable
    unbreakable(boolean unbreakable)
    Sets the item as unbreakable

    Methods inherited from class java.lang.Object

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

    • BaseItemBuilder

      protected BaseItemBuilder(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
  • Method Details

    • serializeComponent

      @NotNull protected @NotNull Object serializeComponent(@NotNull @NotNull net.kyori.adventure.text.Component component)
      Serializes the component with the right ComponentSerializer for the current MC version Expects Components to be pre-parsed by CoreFramework's TextUtility
      Parameters:
      component - component to serialize (already parsed)
      Returns:
      the serialized representation of the component
    • deserializeComponent

      @NotNull protected @NotNull net.kyori.adventure.text.Component deserializeComponent(@NotNull @NotNull Object obj)
      Deserializes the object with the right ComponentSerializer for the current MC version
      Parameters:
      obj - object to deserialize
      Returns:
      the component
    • name

      @NotNull @Contract("_ -> this") public B name(@NotNull @NotNull net.kyori.adventure.text.Component name)
      Sets the display name of the item using Component Component should be pre-parsed by CoreFramework's TextUtility
      Parameters:
      name - The Component name (pre-parsed)
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • amount

      @NotNull @Contract("_ -> this") public B amount(int amount)
      Sets the amount of items
      Parameters:
      amount - the amount of items
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • lore

      @NotNull @Contract("_ -> this") public B lore(@Nullable @Nullable net.kyori.adventure.text.Component @NotNull ... lore)
      Set the lore lines of an item Components should be pre-parsed by CoreFramework's TextUtility
      Parameters:
      lore - Lore lines as varargs (pre-parsed)
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • lore

      @NotNull @Contract("_ -> this") public B lore(@NotNull @NotNull List<@Nullable net.kyori.adventure.text.Component> lore)
      Set the lore lines of an item Components should be pre-parsed by CoreFramework's TextUtility
      Parameters:
      lore - A List with the lore lines (pre-parsed)
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • lore

      @NotNull @Contract("_ -> this") public B lore(@NotNull @NotNull Consumer<List<@Nullable net.kyori.adventure.text.Component>> lore)
      Consumer for freely adding to the lore Components should be pre-parsed by CoreFramework's TextUtility
      Parameters:
      lore - A Consumer with the List of lore Component
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • enchant

      @NotNull @Contract("_, _, _ -> this") public B enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment, int level, boolean ignoreLevelRestriction)
      Enchants the ItemStack
      Parameters:
      enchantment - The Enchantment to add
      level - The level of the Enchantment
      ignoreLevelRestriction - If should or not ignore it
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • enchant

      @NotNull @Contract("_, _ -> this") public B enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment, int level)
      Enchants the ItemStack
      Parameters:
      enchantment - The Enchantment to add
      level - The level of the Enchantment
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • enchant

      @NotNull @Contract("_ -> this") public B enchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment)
      Enchants the ItemStack
      Parameters:
      enchantment - The Enchantment to add
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • enchant

      @NotNull @Contract("_, _ -> this") public B enchant(@NotNull @NotNull Map<org.bukkit.enchantments.Enchantment,Integer> enchantments, boolean ignoreLevelRestriction)
      Enchants the ItemStack with the specified map where the value is the level of the key's enchantment
      Parameters:
      enchantments - Enchantments to add
      ignoreLevelRestriction - If level restriction should be ignored
      Returns:
      ItemBuilder
      Since:
      3.1.2
    • enchant

      @NotNull @Contract("_ -> this") public B enchant(@NotNull @NotNull Map<org.bukkit.enchantments.Enchantment,Integer> enchantments)
      Enchants the ItemStack with the specified map where the value is the level of the key's enchantment
      Parameters:
      enchantments - Enchantments to add
      Returns:
      ItemBuilder
      Since:
      3.1.2
    • disenchant

      @NotNull @Contract("_ -> this") public B disenchant(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment)
      Disenchants a certain Enchantment from the ItemStack
      Parameters:
      enchantment - The Enchantment to remove
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • flags

      @NotNull @Contract("_ -> this") public B flags(@NotNull @NotNull org.bukkit.inventory.ItemFlag... flags)
      Add an ItemFlag to the item
      Parameters:
      flags - The ItemFlag to add
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • unbreakable

      @NotNull @Contract(" -> this") public B unbreakable()
      Makes the ItemStack unbreakable
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • unbreakable

      @NotNull @Contract("_ -> this") public B unbreakable(boolean unbreakable)
      Sets the item as unbreakable
      Parameters:
      unbreakable - If should or not be unbreakable
      Returns:
      ItemBuilder
    • glow

      @NotNull @Contract(" -> this") public B glow()
      Makes the ItemStack glow
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • glow

      @NotNull @Contract("_ -> this") public B glow(boolean glow)
      Adds or removes the ItemStack glow
      Parameters:
      glow - Should the item glow
      Returns:
      ItemBuilder
    • pdc

      @NotNull @Contract("_ -> this") public B pdc(@NotNull @NotNull Consumer<org.bukkit.persistence.PersistentDataContainer> consumer)
      Consumer for applying PersistentDataContainer to the item This method will only work on versions above 1.14
      Parameters:
      consumer - The Consumer with the PDC
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • model

      @NotNull @Contract("_ -> this") public B model(int modelData)
      Sets the custom model data of the item Added in 1.13
      Parameters:
      modelData - The custom model data from the resource pack
      Returns:
      ItemBuilder
      Since:
      3.0.0
    • color

      @NotNull @Contract("_ -> this") public B color(@NotNull @NotNull org.bukkit.Color color)
      Color an ItemStack
      Parameters:
      color - color
      Returns:
      BaseItemBuilder
      Since:
      3.0.3
      See Also:
      • LeatherArmorMeta.setColor(Color)
      • MapMeta.setColor(Color)
    • setNBT

      @NotNull @Contract("_, _ -> this") public B setNBT(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Sets NBT tag to the ItemStack
      Parameters:
      key - The NBT key
      value - The NBT value
      Returns:
      ItemBuilder
    • setNBT

      @NotNull @Contract("_, _ -> this") public B setNBT(@NotNull @NotNull String key, boolean value)
      Sets NBT tag to the ItemStack
      Parameters:
      key - The NBT key
      value - The NBT value
      Returns:
      ItemBuilder
    • removeNBT

      @NotNull @Contract("_ -> this") public B removeNBT(@NotNull @NotNull String key)
      Removes NBT tag from the ItemStack
      Parameters:
      key - The NBT key
      Returns:
      ItemBuilder
    • build

      @NotNull public @NotNull org.bukkit.inventory.ItemStack build()
      Builds the item into ItemStack
      Returns:
      The fully built ItemStack
    • asModalItem

      @NotNull @Contract(" -> new") public @NotNull ModalItem asModalItem()
      Creates a ModalItem instead of an ItemStack
      Returns:
      A ModalItem with no ModalAction
    • asModalItem

      @NotNull @Contract("_ -> new") public @NotNull ModalItem asModalItem(@NotNull @NotNull ModalAction<org.bukkit.event.inventory.InventoryClickEvent> action)
      Creates a ModalItem instead of an ItemStack
      Parameters:
      action - The ModalAction to apply to the item
      Returns:
      A ModalItem with ModalAction
    • getItemStack

      @NotNull protected @NotNull org.bukkit.inventory.ItemStack getItemStack()
      Package private getter for extended builders
      Returns:
      The ItemStack
    • setItemStack

      protected void setItemStack(@NotNull @NotNull org.bukkit.inventory.ItemStack itemStack)
      Package private setter for the extended builders
      Parameters:
      itemStack - The ItemStack
    • getMeta

      @NotNull protected @NotNull org.bukkit.inventory.meta.ItemMeta getMeta()
      Package private getter for extended builders
      Returns:
      The ItemMeta
    • setMeta

      protected void setMeta(@NotNull @NotNull org.bukkit.inventory.meta.ItemMeta meta)
      Package private setter for the extended builders
      Parameters:
      meta - The ItemMeta