Class ItemEnchantmentQueryImpl
- All Implemented Interfaces:
ItemEnchantmentQuery
ItemEnchantmentQuery that delegates to
ItemStorage and EnchantmentRegistryManager.
This implementation follows the facade pattern - it provides a more ergonomic API while delegating all actual operations to existing storage and registry components.
Null Safety: All methods handle null inputs gracefully as specified by the interface contract.
- Since:
- 0.2.0
-
Constructor Summary
ConstructorsConstructorDescriptionItemEnchantmentQueryImpl(@NotNull ItemStorage itemStorage, @NotNull EnchantmentRegistryManager registryManager) Creates a new query facade. -
Method Summary
Modifier and TypeMethodDescription@NotNull Map<EnchantmentDefinition, Integer> getAllEnchantments(@Nullable org.bukkit.inventory.ItemStack item) Gets all artificial enchantments on an item.@NotNull Set<EnchantmentDefinition> getEnchantmentsFor(@Nullable org.bukkit.Material material) Gets all enchantments that can be applied to a specific material.intgetHighestLevel(@Nullable org.bukkit.inventory.ItemStack item) Gets the highest enchantment level on an item.intgetLevel(@Nullable org.bukkit.inventory.ItemStack item, @NotNull EnchantmentDefinition enchantment) Gets the level of a specific enchantment on an item.intgetLevel(@Nullable org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.NamespacedKey key) Gets the level of an enchantment by its registry key.intgetTotalEnchantmentLevel(@Nullable org.bukkit.inventory.ItemStack item) Gets the total level of all enchantments on an item.booleanhasAllEnchantments(@Nullable org.bukkit.inventory.ItemStack item, @NotNull EnchantmentDefinition... enchantments) Checks if multiple enchantments are present on an item.booleanhasAnyEnchantment(@Nullable org.bukkit.inventory.ItemStack item, @NotNull EnchantmentDefinition... enchantments) Checks if any of the specified enchantments are present on an item.booleanhasEnchantment(@Nullable org.bukkit.inventory.ItemStack item, @NotNull EnchantmentDefinition enchantment) Checks if an item has a specific enchantment.booleanhasEnchantment(@Nullable org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.NamespacedKey key) Checks if an item has an enchantment by its registry key.booleanisEnchanted(@Nullable org.bukkit.inventory.ItemStack item) Checks if an item has any custom enchantment.
-
Constructor Details
-
ItemEnchantmentQueryImpl
public ItemEnchantmentQueryImpl(@NotNull @NotNull ItemStorage itemStorage, @NotNull @NotNull EnchantmentRegistryManager registryManager) Creates a new query facade.- Parameters:
itemStorage- the item storage to delegate to (must not be null)registryManager- the registry manager for enchantment lookups (must not be null)
-
-
Method Details
-
hasEnchantment
public boolean hasEnchantment(@Nullable @Nullable org.bukkit.inventory.ItemStack item, @NotNull @NotNull EnchantmentDefinition enchantment) Description copied from interface:ItemEnchantmentQueryChecks if an item has a specific enchantment.Returns false if the item is null or the enchantment is not present.
- Specified by:
hasEnchantmentin interfaceItemEnchantmentQuery- Parameters:
item- the item to check (null-safe)enchantment- the enchantment to look for (must not be null)- Returns:
- true if the item has the enchantment at any level
-
hasEnchantment
public boolean hasEnchantment(@Nullable @Nullable org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.NamespacedKey key) Description copied from interface:ItemEnchantmentQueryChecks if an item has an enchantment by its registry key.Returns false if the item is null, the key is not found in the registry, or the enchantment is not present on the item.
- Specified by:
hasEnchantmentin interfaceItemEnchantmentQuery- Parameters:
item- the item to check (null-safe)key- the enchantment's namespaced key (must not be null)- Returns:
- true if the item has the enchantment at any level
-
getLevel
public int getLevel(@Nullable @Nullable org.bukkit.inventory.ItemStack item, @NotNull @NotNull EnchantmentDefinition enchantment) Description copied from interface:ItemEnchantmentQueryGets the level of a specific enchantment on an item.Returns 0 if the item is null, doesn't have the enchantment, or the enchantment is not registered.
- Specified by:
getLevelin interfaceItemEnchantmentQuery- Parameters:
item- the item to query (null-safe)enchantment- the enchantment to check (must not be null)- Returns:
- the enchantment level, or 0 if not present
-
getLevel
public int getLevel(@Nullable @Nullable org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.NamespacedKey key) Description copied from interface:ItemEnchantmentQueryGets the level of an enchantment by its registry key.Returns 0 if the item is null, the enchantment is not found in the registry, or the enchantment is not present on the item.
- Specified by:
getLevelin interfaceItemEnchantmentQuery- Parameters:
item- the item to query (null-safe)key- the enchantment's namespaced key (must not be null)- Returns:
- the enchantment level, or 0 if not present
-
getAllEnchantments
@NotNull public @NotNull Map<EnchantmentDefinition,Integer> getAllEnchantments(@Nullable @Nullable org.bukkit.inventory.ItemStack item) Description copied from interface:ItemEnchantmentQueryGets all artificial enchantments on an item.Returns a map of enchantment definitions to their levels. Only enchantments registered through this API are included; vanilla enchantments are excluded.
The returned map is unmodifiable and represents a snapshot of the item's state at the time of the call. Returns an empty map if the item is null.
- Specified by:
getAllEnchantmentsin interfaceItemEnchantmentQuery- Parameters:
item- the item to query (null-safe)- Returns:
- an unmodifiable map of enchantments to levels (never null)
-
isEnchanted
public boolean isEnchanted(@Nullable @Nullable org.bukkit.inventory.ItemStack item) Description copied from interface:ItemEnchantmentQueryChecks if an item has any custom enchantment.Returns true if the item has at least one artificial enchantment registered through this API. Returns false if the item is null or has no custom enchantments.
- Specified by:
isEnchantedin interfaceItemEnchantmentQuery- Parameters:
item- the item to check (null-safe)- Returns:
- true if the item has any custom enchantment
-
getEnchantmentsFor
@NotNull public @NotNull Set<EnchantmentDefinition> getEnchantmentsFor(@Nullable @Nullable org.bukkit.Material material) Description copied from interface:ItemEnchantmentQueryGets all enchantments that can be applied to a specific material.Returns a set of all registered enchantments that are applicable to the given material. This is useful for enchanting interfaces or checking what enchantments are available for a tool type.
The returned set is unmodifiable. Returns an empty set if the material is null or no enchantments are applicable.
- Specified by:
getEnchantmentsForin interfaceItemEnchantmentQuery- Parameters:
material- the material to check (null-safe)- Returns:
- an unmodifiable set of applicable enchantments (never null)
-
hasAllEnchantments
public boolean hasAllEnchantments(@Nullable @Nullable org.bukkit.inventory.ItemStack item, @NotNull @NotNull EnchantmentDefinition... enchantments) Description copied from interface:ItemEnchantmentQueryChecks if multiple enchantments are present on an item.Returns true only if ALL specified enchantments are present on the item. Returns false if the item is null, the enchantments array is empty, or any enchantment is missing.
- Specified by:
hasAllEnchantmentsin interfaceItemEnchantmentQuery- Parameters:
item- the item to check (null-safe)enchantments- the enchantments to look for (must not be null or empty)- Returns:
- true if all enchantments are present
-
hasAnyEnchantment
public boolean hasAnyEnchantment(@Nullable @Nullable org.bukkit.inventory.ItemStack item, @NotNull @NotNull EnchantmentDefinition... enchantments) Description copied from interface:ItemEnchantmentQueryChecks if any of the specified enchantments are present on an item.Returns true if AT LEAST ONE of the specified enchantments is present on the item. Returns false if the item is null, the enchantments array is empty, or none of the enchantments are present.
- Specified by:
hasAnyEnchantmentin interfaceItemEnchantmentQuery- Parameters:
item- the item to check (null-safe)enchantments- the enchantments to look for (must not be null or empty)- Returns:
- true if any enchantment is present
-
getTotalEnchantmentLevel
public int getTotalEnchantmentLevel(@Nullable @Nullable org.bukkit.inventory.ItemStack item) Description copied from interface:ItemEnchantmentQueryGets the total level of all enchantments on an item.Returns the sum of all enchantment levels. Returns 0 if the item is null or has no enchantments.
- Specified by:
getTotalEnchantmentLevelin interfaceItemEnchantmentQuery- Parameters:
item- the item to query (null-safe)- Returns:
- the sum of all enchantment levels
-
getHighestLevel
public int getHighestLevel(@Nullable @Nullable org.bukkit.inventory.ItemStack item) Description copied from interface:ItemEnchantmentQueryGets the highest enchantment level on an item.Returns the maximum level among all enchantments on the item. Returns 0 if the item is null or has no enchantments.
- Specified by:
getHighestLevelin interfaceItemEnchantmentQuery- Parameters:
item- the item to query (null-safe)- Returns:
- the highest enchantment level, or 0 if none
-