Class EnchantmentRegistryManager

java.lang.Object
io.artificial.enchantments.internal.EnchantmentRegistryManager

public final class EnchantmentRegistryManager extends Object
Internal registry manager for tracking enchantment definitions.

This class maintains the source of truth for all registered enchantments and coordinates with the Paper native registry during bootstrap. It provides thread-safe storage and indexing for efficient lookup by key or material.

Key responsibilities:

  • Maintain primary storage of enchantment definitions
  • Index enchantments by applicable materials for fast lookup
  • Track pending native registrations
  • Coordinate with PaperRegistryBridge for bidirectional lookup
Since:
0.1.0
  • Method Details

    • getInstance

      public static EnchantmentRegistryManager getInstance()
      Gets the singleton instance of the registry manager.
      Returns:
      the shared EnchantmentRegistryManager instance
    • register

      public boolean register(@NotNull @NotNull EnchantmentDefinition definition)
      Registers an enchantment definition. This makes it available for native registration during bootstrap.
      Parameters:
      definition - the enchantment definition to register
      Returns:
      true if the enchantment was newly registered, false if it already existed
    • unregister

      public boolean unregister(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Unregisters an enchantment definition.
      Parameters:
      key - the namespaced key of the enchantment to unregister
      Returns:
      true if an enchantment was removed, false if not found
    • get

      @NotNull public @NotNull Optional<EnchantmentDefinition> get(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Gets an enchantment definition by its key.
      Parameters:
      key - the enchantment's namespaced key
      Returns:
      optional containing the definition, or empty if not found
    • getEnchantment

      @Nullable public @Nullable EnchantmentDefinition getEnchantment(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Gets an enchantment definition by its key (nullable variant).
      Parameters:
      key - the enchantment's namespaced key
      Returns:
      the definition, or null if not found
    • getAll

      @NotNull public @NotNull Collection<EnchantmentDefinition> getAll()
      Gets all registered enchantment definitions.
      Returns:
      unmodifiable collection of all enchantments
    • getForMaterial

      @NotNull public @NotNull Set<EnchantmentDefinition> getForMaterial(@NotNull org.bukkit.Material material)
      Gets all enchantments applicable to a specific material.
      Parameters:
      material - the material to check
      Returns:
      unmodifiable set of applicable enchantment definitions
    • getPendingRegistrations

      @NotNull public @NotNull Collection<EnchantmentDefinition> getPendingRegistrations()
      Returns all enchantments pending native registration. Called during the bootstrap registry compose event.
      Returns:
      collection of enchantment definitions awaiting native registration
    • markNativeRegistered

      public void markNativeRegistered(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Marks an enchantment as successfully registered to native registry.
      Parameters:
      key - the namespaced key of the enchantment to mark as registered
    • clearPendingNativeRegistration

      public void clearPendingNativeRegistration(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Removes an enchantment from the pending native registration queue without marking it as registered. Called when native registration fails so the pending set does not accumulate stale entries.
      Parameters:
      key - the namespaced key of the enchantment whose pending state should be cleared
    • isNativeRegistered

      public boolean isNativeRegistered(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Checks if an enchantment has been registered to the native registry.
      Parameters:
      key - the namespaced key of the enchantment to check
      Returns:
      true if the enchantment has been registered to the native registry
    • markNativeRegistrationClosed

      public void markNativeRegistrationClosed()
      Marks the native registry composition window as closed.
    • isNativeRegistrationClosed

      public boolean isNativeRegistrationClosed()
      Checks whether native enchantment registration is closed.
      Returns:
      true once the Paper enchantment registry compose event has run
    • clear

      public void clear()
      Clears all registrations. Used primarily for testing.