Class EnchantedBookBuilderImpl
- All Implemented Interfaces:
EnchantedBook.Builder
- Since:
- 0.2.0
-
Constructor Summary
ConstructorsConstructorDescriptionEnchantedBookBuilderImpl(@NotNull ItemStorage itemStorage) Creates a new enchanted book builder. -
Method Summary
Modifier and TypeMethodDescription@NotNull org.bukkit.inventory.ItemStackbuild()Builds and returns the enchanted book.displayName(@Nullable String displayName) Sets a custom display name for the book.Adds lore lines to the book.reset()Resets the builder to its initial state.treasure(boolean treasure) Sets whether the book is a "treasure" book (from chests/loot).withEnchantment(@NotNull EnchantmentDefinition enchantment, int level) Adds an enchantment to the book at the specified level.withEnchantment(@NotNull org.bukkit.NamespacedKey key, int level) Adds an enchantment by its registry key.
-
Constructor Details
-
EnchantedBookBuilderImpl
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:
withEnchantmentin interfaceEnchantedBook.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:
withEnchantmentin interfaceEnchantedBook.Builder- Parameters:
key- the enchantment's namespaced key (must not be null)level- the level to apply- Returns:
- this builder for chaining
-
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:
displayNamein interfaceEnchantedBook.Builder- Parameters:
displayName- the custom display name, or null for default- Returns:
- this builder for chaining
-
lore
Adds lore lines to the book.These lines appear below the enchantment descriptions in the book's tooltip.
- Specified by:
lorein interfaceEnchantedBook.Builder- Parameters:
lore- the lore lines to add (must not be null)- Returns:
- this builder for chaining
-
treasure
Sets whether the book is a "treasure" book (from chests/loot).This affects anvil cost calculation - treasure books cost more.
- Specified by:
treasurein interfaceEnchantedBook.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:
buildin interfaceEnchantedBook.Builder- Returns:
- the created enchanted book
-
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:
resetin interfaceEnchantedBook.Builder- Returns:
- this builder for chaining
-