Class EnchantedBookBuilderImpl

java.lang.Object
io.artificial.enchantments.internal.book.EnchantedBookBuilderImpl
All Implemented Interfaces:
EnchantedBook.Builder

public class EnchantedBookBuilderImpl extends Object implements EnchantedBook.Builder
Builder implementation for creating enchanted books.
Since:
0.2.0
  • Constructor Details

    • EnchantedBookBuilderImpl

      public EnchantedBookBuilderImpl(@NotNull @NotNull ItemStorage itemStorage)
      Creates a new enchanted book builder.
      Parameters:
      itemStorage - the item storage for applying enchantments
  • Method Details

    • withEnchantment

      @NotNull public EnchantedBook.Builder withEnchantment(@NotNull @NotNull EnchantmentDefinition enchantment, int level)
      Adds an enchantment to the book at the specified level.

      The level must be within the enchantment's defined min/max bounds. If the enchantment is already present, the higher level is kept (matching vanilla behavior for combining books).

      Specified by:
      withEnchantment in interface EnchantedBook.Builder
      Parameters:
      enchantment - the enchantment to add (must not be null)
      level - the level to apply (must be within bounds)
      Returns:
      this builder for chaining
    • withEnchantment

      @NotNull public EnchantedBook.Builder withEnchantment(@NotNull @NotNull org.bukkit.NamespacedKey key, int level)
      Adds an enchantment by its registry key.

      This is a convenience method that looks up the definition before adding.

      Specified by:
      withEnchantment in interface EnchantedBook.Builder
      Parameters:
      key - the enchantment's namespaced key (must not be null)
      level - the level to apply
      Returns:
      this builder for chaining
    • displayName

      @NotNull public EnchantedBook.Builder displayName(@Nullable @Nullable String displayName)
      Sets a custom display name for the book.

      If not set, the book will use the default name based on its enchantments (e.g., "Enchanted Book" or "Book of Life Steal").

      Specified by:
      displayName in interface EnchantedBook.Builder
      Parameters:
      displayName - the custom display name, or null for default
      Returns:
      this builder for chaining
    • lore

      @NotNull public EnchantedBook.Builder lore(@NotNull @NotNull String... lore)
      Adds lore lines to the book.

      These lines appear below the enchantment descriptions in the book's tooltip.

      Specified by:
      lore in interface EnchantedBook.Builder
      Parameters:
      lore - the lore lines to add (must not be null)
      Returns:
      this builder for chaining
    • treasure

      @NotNull public EnchantedBook.Builder treasure(boolean treasure)
      Sets whether the book is a "treasure" book (from chests/loot).

      This affects anvil cost calculation - treasure books cost more.

      Specified by:
      treasure in interface EnchantedBook.Builder
      Parameters:
      treasure - true if this is a treasure book
      Returns:
      this builder for chaining
    • build

      @NotNull public @NotNull org.bukkit.inventory.ItemStack build()
      Builds and returns the enchanted book.

      The book is created as an ENCHANTED_BOOK item with all specified enchantments stored in native ItemMeta. The returned item is a new ItemStack instance.

      Specified by:
      build in interface EnchantedBook.Builder
      Returns:
      the created enchanted book
    • reset

      @NotNull public EnchantedBook.Builder reset()
      Resets the builder to its initial state.

      This clears all enchantments and settings, allowing the builder to be reused for creating another book.

      Specified by:
      reset in interface EnchantedBook.Builder
      Returns:
      this builder for chaining