Class PaperRegistryBridge

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

public final class PaperRegistryBridge extends Object
Bridge between the library's enchantment registry and Paper's native enchantment registry. Provides bidirectional lookup and validation.

This class enables seamless interoperability between the library's EnchantmentDefinition format and Paper's native Enchantment registry. It handles:

  • Bidirectional lookup between library and native enchantments
  • Registration coordination between internal and native registries
  • Validation of native registration status
Since:
0.2.0
  • Method Details

    • getInstance

      @NotNull public static @NotNull PaperRegistryBridge getInstance()
      Gets the singleton instance of the registry bridge.
      Returns:
      the shared PaperRegistryBridge instance
    • getDefinition

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

      @Nullable public @Nullable org.bukkit.enchantments.Enchantment getNativeEnchantment(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Gets the native Paper Enchantment by its key.

      Returns null if the enchantment hasn't been registered to the native registry yet.

      Parameters:
      key - the enchantment's namespaced key
      Returns:
      the native Paper Enchantment, or null if not yet registered
    • isNativeRegistered

      public boolean isNativeRegistered(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Checks if an enchantment is registered in the native Paper registry.
      Parameters:
      key - the enchantment's namespaced key
      Returns:
      true if registered in the native Paper registry
    • getAllDefinitions

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

      @NotNull public @NotNull Set<EnchantmentDefinition> getEnchantmentsForMaterial(@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
    • registerEnchantment

      public boolean registerEnchantment(@NotNull @NotNull EnchantmentDefinition definition)
      Registers an enchantment definition with both the internal registry and prepares it for native Paper registration.

      Returns false if the enchantment is already native-registered.

      Parameters:
      definition - the enchantment definition to register
      Returns:
      true if registered successfully, false if already native-registered
    • unregisterEnchantment

      public boolean unregisterEnchantment(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Unregisters an enchantment from the internal tracking.

      Note: Native unregistration is not supported after Paper's registry compose window closes. This only removes from internal tracking.

      Parameters:
      key - the enchantment's namespaced key
      Returns:
      true if unregistered, false if not found
    • fromNative

      @Nullable public @Nullable EnchantmentDefinition fromNative(@NotNull @NotNull org.bukkit.enchantments.Enchantment enchantment)
      Converts a native Paper Enchantment to the library's EnchantmentDefinition.
      Parameters:
      enchantment - the native Paper Enchantment
      Returns:
      the library EnchantmentDefinition, or null if not found
    • toNative

      @Nullable public @Nullable org.bukkit.enchantments.Enchantment toNative(@NotNull @NotNull EnchantmentDefinition definition)
      Gets the native Paper Enchantment for a library definition.
      Parameters:
      definition - the library enchantment definition
      Returns:
      the native Paper Enchantment, or null if not yet registered