Class EnchantedBookImpl
java.lang.Object
io.artificial.enchantments.internal.book.EnchantedBookImpl
- All Implemented Interfaces:
EnchantedBook
Implementation of
EnchantedBook using native ItemMeta storage.
This implementation follows the native-first policy, storing enchantments directly in the book's EnchantmentStorageMeta. No auxiliary NBT is used for enchantment data.
- Since:
- 0.2.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.artificial.enchantments.api.book.EnchantedBook
EnchantedBook.Builder -
Constructor Summary
ConstructorsConstructorDescriptionEnchantedBookImpl(@NotNull ItemStorage itemStorage) Creates a new enchanted book implementation. -
Method Summary
Modifier and TypeMethodDescription@NotNull EnchantedBook.Builderbuilder()Gets a builder for creating enchanted books.getAllEnchantmentKeys(@NotNull org.bukkit.inventory.ItemStack book) Gets all enchantment keys on a book as NamespacedKey to level mapping.intgetEnchantmentLevel(@NotNull org.bukkit.inventory.ItemStack book, @NotNull EnchantmentDefinition enchantment) Gets the level of a specific artificial enchantment on a book.intgetEnchantmentLevel(@NotNull org.bukkit.inventory.ItemStack book, @NotNull org.bukkit.NamespacedKey key) Gets the level of an artificial enchantment by its key.@NotNull Map<EnchantmentDefinition, Integer> getEnchantments(@NotNull org.bukkit.inventory.ItemStack book) Gets all artificial enchantments stored on a book.booleanhasCustomEnchantments(@NotNull org.bukkit.inventory.ItemStack book) Checks if an enchanted book contains custom (artificial) enchantments.booleanhasEnchantment(@NotNull org.bukkit.inventory.ItemStack book, @NotNull EnchantmentDefinition enchantment) Checks if a specific artificial enchantment exists on a book.booleanhasEnchantment(@NotNull org.bukkit.inventory.ItemStack book, @NotNull org.bukkit.NamespacedKey key) Checks if an artificial enchantment exists by its key.booleanisEnchantedBook(@NotNull org.bukkit.inventory.ItemStack item) Checks if an item is an enchanted book (vanilla or custom).
-
Constructor Details
-
EnchantedBookImpl
Creates a new enchanted book implementation.- Parameters:
itemStorage- the item storage for enchantment operations
-
-
Method Details
-
isEnchantedBook
public boolean isEnchantedBook(@NotNull @NotNull org.bukkit.inventory.ItemStack item) Checks if an item is an enchanted book (vanilla or custom).This returns true for both vanilla ENCHANTED_BOOK items and books created through this API.
- Specified by:
isEnchantedBookin interfaceEnchantedBook- Parameters:
item- the item to check (must not be null)- Returns:
- true if the item is an enchanted book
-
hasCustomEnchantments
public boolean hasCustomEnchantments(@NotNull @NotNull org.bukkit.inventory.ItemStack book) Checks if an enchanted book contains custom (artificial) enchantments.This distinguishes between books with only vanilla enchantments and books that have enchantments registered through this API.
- Specified by:
hasCustomEnchantmentsin interfaceEnchantedBook- Parameters:
book- the book to check (must not be null)- Returns:
- true if the book has at least one artificial enchantment
-
getEnchantments
@NotNull public @NotNull Map<EnchantmentDefinition,Integer> getEnchantments(@NotNull @NotNull org.bukkit.inventory.ItemStack book) Gets all artificial enchantments stored on a book.Returns a map of enchantment definitions to their levels. Only enchantments registered through this API are included.
- Specified by:
getEnchantmentsin interfaceEnchantedBook- Parameters:
book- the book to query (must not be null)- Returns:
- unmodifiable map of enchantments to levels (never null, may be empty)
-
getEnchantmentLevel
public int getEnchantmentLevel(@NotNull @NotNull org.bukkit.inventory.ItemStack book, @NotNull @NotNull EnchantmentDefinition enchantment) Gets the level of a specific artificial enchantment on a book.- Specified by:
getEnchantmentLevelin interfaceEnchantedBook- Parameters:
book- the book to query (must not be null)enchantment- the enchantment to look for (must not be null)- Returns:
- the enchantment level, or 0 if not present
-
getEnchantmentLevel
public int getEnchantmentLevel(@NotNull @NotNull org.bukkit.inventory.ItemStack book, @NotNull @NotNull org.bukkit.NamespacedKey key) Gets the level of an artificial enchantment by its key.- Specified by:
getEnchantmentLevelin interfaceEnchantedBook- Parameters:
book- the book to query (must not be null)key- the enchantment's namespaced key (must not be null)- Returns:
- the enchantment level, or 0 if not present
-
getAllEnchantmentKeys
@NotNull public @NotNull Map<org.bukkit.NamespacedKey,Integer> getAllEnchantmentKeys(@NotNull @NotNull org.bukkit.inventory.ItemStack book) Gets all enchantment keys on a book as NamespacedKey to level mapping.This includes both vanilla and artificial enchantments.
- Specified by:
getAllEnchantmentKeysin interfaceEnchantedBook- Parameters:
book- the book to query (must not be null)- Returns:
- unmodifiable map of all enchantment keys to levels
-
hasEnchantment
public boolean hasEnchantment(@NotNull @NotNull org.bukkit.inventory.ItemStack book, @NotNull @NotNull EnchantmentDefinition enchantment) Checks if a specific artificial enchantment exists on a book.- Specified by:
hasEnchantmentin interfaceEnchantedBook- Parameters:
book- the book to check (must not be null)enchantment- the enchantment to look for (must not be null)- Returns:
- true if the book has the enchantment at any level
-
hasEnchantment
public boolean hasEnchantment(@NotNull @NotNull org.bukkit.inventory.ItemStack book, @NotNull @NotNull org.bukkit.NamespacedKey key) Checks if an artificial enchantment exists by its key.- Specified by:
hasEnchantmentin interfaceEnchantedBook- Parameters:
book- the book to check (must not be null)key- the enchantment's namespaced key (must not be null)- Returns:
- true if the book has the enchantment at any level
-
builder
Gets a builder for creating enchanted books.The returned builder can be used to construct books with one or more enchantments. Books are created as ENCHANTED_BOOK items with enchantments stored in native ItemMeta.
- Specified by:
builderin interfaceEnchantedBook- Returns:
- a new book builder instance
-