Class ItemEnchantmentQueryImpl

java.lang.Object
io.artificial.enchantments.internal.query.ItemEnchantmentQueryImpl
All Implemented Interfaces:
ItemEnchantmentQuery

public class ItemEnchantmentQueryImpl extends Object implements ItemEnchantmentQuery
Implementation of 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 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: ItemEnchantmentQuery
      Checks if an item has a specific enchantment.

      Returns false if the item is null or the enchantment is not present.

      Specified by:
      hasEnchantment in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Checks 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:
      hasEnchantment in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Gets 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:
      getLevel in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Gets 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:
      getLevel in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Gets 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:
      getAllEnchantments in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Checks 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:
      isEnchanted in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Gets 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:
      getEnchantmentsFor in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Checks 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:
      hasAllEnchantments in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Checks 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:
      hasAnyEnchantment in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Gets 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:
      getTotalEnchantmentLevel in interface ItemEnchantmentQuery
      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: ItemEnchantmentQuery
      Gets 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:
      getHighestLevel in interface ItemEnchantmentQuery
      Parameters:
      item - the item to query (null-safe)
      Returns:
      the highest enchantment level, or 0 if none