Class LootModifierRegistryImpl

java.lang.Object
io.artificial.enchantments.internal.loot.LootModifierRegistryImpl
All Implemented Interfaces:
LootModifierRegistry

public final class LootModifierRegistryImpl extends Object implements LootModifierRegistry
Thread-safe implementation of LootModifierRegistry.

This implementation uses concurrent collections to ensure thread safety for all registry operations. The registry maintains a map of enchantments to their registered modifiers, with each enchantment having a list of modifiers that are invoked in registration order.

Thread Safety:

  • Registration is thread-safe
  • Read operations are lock-free
  • Modifier lists use CopyOnWriteArrayList for safe iteration
  • All operations are non-blocking
Since:
0.4.0
  • Constructor Details

    • LootModifierRegistryImpl

      public LootModifierRegistryImpl()
      Creates a new empty registry.
  • Method Details

    • register

      public void register(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier)
      Description copied from interface: LootModifierRegistry
      Registers a loot modifier for an enchantment.

      The modifier will be invoked whenever a player breaks a block with a tool containing this enchantment. Multiple modifiers can be registered for the same enchantment - they will all be invoked in registration order.

      Registration is idempotent - registering the same modifier twice for the same enchantment has no effect.

      Specified by:
      register in interface LootModifierRegistry
      Parameters:
      enchantment - the enchantment to register the modifier for
      modifier - the modifier to register
    • unregister

      public boolean unregister(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier)
      Description copied from interface: LootModifierRegistry
      Unregisters a specific loot modifier from an enchantment.

      Removes a previously registered modifier. If the modifier was not registered for this enchantment, this method does nothing.

      Specified by:
      unregister in interface LootModifierRegistry
      Parameters:
      enchantment - the enchantment to remove the modifier from
      modifier - the modifier to unregister
      Returns:
      true if the modifier was found and removed, false otherwise
    • unregisterAll

      public boolean unregisterAll(@NotNull @NotNull EnchantmentDefinition enchantment)
      Description copied from interface: LootModifierRegistry
      Unregisters all loot modifiers for an enchantment.

      Removes all modifiers for the specified enchantment. After this call, LootModifierRegistry.hasModifier(EnchantmentDefinition) will return false.

      Specified by:
      unregisterAll in interface LootModifierRegistry
      Parameters:
      enchantment - the enchantment to clear modifiers for
      Returns:
      true if any modifiers were removed, false if none existed
    • getModifiers

      @NotNull public @NotNull List<LootModifier> getModifiers(@NotNull @NotNull EnchantmentDefinition enchantment)
      Description copied from interface: LootModifierRegistry
      Specified by:
      getModifiers in interface LootModifierRegistry
      Parameters:
      enchantment - the enchantment to get modifiers for
      Returns:
      list of registered modifiers (may be empty, never null)
    • hasModifier

      public boolean hasModifier(@NotNull @NotNull EnchantmentDefinition enchantment)
      Description copied from interface: LootModifierRegistry
      Checks if an enchantment has any registered loot modifiers.

      This is the primary API for checking if an enchantment affects loot drops. Use this before processing loot modifications.

      Specified by:
      hasModifier in interface LootModifierRegistry
      Parameters:
      enchantment - the enchantment to check
      Returns:
      true if at least one modifier is registered
    • getModifierCount

      public int getModifierCount(@NotNull @NotNull EnchantmentDefinition enchantment)
      Description copied from interface: LootModifierRegistry
      Gets the number of modifiers registered for an enchantment.
      Specified by:
      getModifierCount in interface LootModifierRegistry
      Parameters:
      enchantment - the enchantment to check
      Returns:
      the number of registered modifiers (0 if none)
    • clear

      public void clear()
      Description copied from interface: LootModifierRegistry
      Clears all registrations from this registry.

      Warning: This removes ALL loot modifier registrations from ALL enchantments. This is primarily for cleanup during shutdown.

      Specified by:
      clear in interface LootModifierRegistry
    • isRegistered

      public boolean isRegistered(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier)
      Description copied from interface: LootModifierRegistry
      Checks if a specific modifier is registered for an enchantment.
      Specified by:
      isRegistered in interface LootModifierRegistry
      Parameters:
      enchantment - the enchantment to check
      modifier - the modifier to look for
      Returns:
      true if the modifier is registered for this enchantment
    • getEnchantmentCount

      public int getEnchantmentCount()
      Gets the total number of enchantments with registered modifiers.
      Returns:
      the count of enchantments
    • getTotalModifierCount

      public int getTotalModifierCount()
      Gets the total number of registered modifiers across all enchantments.
      Returns:
      the total modifier count