Class LootModifierRegistryImpl
- All Implemented Interfaces:
LootModifierRegistry
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all registrations from this registry.intGets the total number of enchantments with registered modifiers.intgetModifierCount(@NotNull EnchantmentDefinition enchantment) Gets the number of modifiers registered for an enchantment.@NotNull List<LootModifier> getModifiers(@NotNull EnchantmentDefinition enchantment) Gets all loot modifiers registered for an enchantment.intGets the total number of registered modifiers across all enchantments.booleanhasModifier(@NotNull EnchantmentDefinition enchantment) Checks if an enchantment has any registered loot modifiers.booleanisRegistered(@NotNull EnchantmentDefinition enchantment, @NotNull LootModifier modifier) Checks if a specific modifier is registered for an enchantment.voidregister(@NotNull EnchantmentDefinition enchantment, @NotNull LootModifier modifier) Registers a loot modifier for an enchantment.booleanunregister(@NotNull EnchantmentDefinition enchantment, @NotNull LootModifier modifier) Unregisters a specific loot modifier from an enchantment.booleanunregisterAll(@NotNull EnchantmentDefinition enchantment) Unregisters all loot modifiers for an enchantment.
-
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:LootModifierRegistryRegisters 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:
registerin interfaceLootModifierRegistry- Parameters:
enchantment- the enchantment to register the modifier formodifier- the modifier to register
-
unregister
public boolean unregister(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier) Description copied from interface:LootModifierRegistryUnregisters 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:
unregisterin interfaceLootModifierRegistry- Parameters:
enchantment- the enchantment to remove the modifier frommodifier- the modifier to unregister- Returns:
- true if the modifier was found and removed, false otherwise
-
unregisterAll
Description copied from interface:LootModifierRegistryUnregisters all loot modifiers for an enchantment.Removes all modifiers for the specified enchantment. After this call,
LootModifierRegistry.hasModifier(EnchantmentDefinition)will return false.- Specified by:
unregisterAllin interfaceLootModifierRegistry- 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:LootModifierRegistryGets all loot modifiers registered for an enchantment.Returns the list of modifiers in registration order. The returned list is unmodifiable - use
LootModifierRegistry.register(io.artificial.enchantments.api.EnchantmentDefinition, io.artificial.enchantments.api.loot.LootModifier)andLootModifierRegistry.unregister(io.artificial.enchantments.api.EnchantmentDefinition, io.artificial.enchantments.api.loot.LootModifier)to modify registrations.- Specified by:
getModifiersin interfaceLootModifierRegistry- Parameters:
enchantment- the enchantment to get modifiers for- Returns:
- list of registered modifiers (may be empty, never null)
-
hasModifier
Description copied from interface:LootModifierRegistryChecks 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:
hasModifierin interfaceLootModifierRegistry- Parameters:
enchantment- the enchantment to check- Returns:
- true if at least one modifier is registered
-
getModifierCount
Description copied from interface:LootModifierRegistryGets the number of modifiers registered for an enchantment.- Specified by:
getModifierCountin interfaceLootModifierRegistry- Parameters:
enchantment- the enchantment to check- Returns:
- the number of registered modifiers (0 if none)
-
clear
public void clear()Description copied from interface:LootModifierRegistryClears all registrations from this registry.Warning: This removes ALL loot modifier registrations from ALL enchantments. This is primarily for cleanup during shutdown.
- Specified by:
clearin interfaceLootModifierRegistry
-
isRegistered
public boolean isRegistered(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull @NotNull LootModifier modifier) Description copied from interface:LootModifierRegistryChecks if a specific modifier is registered for an enchantment.- Specified by:
isRegisteredin interfaceLootModifierRegistry- Parameters:
enchantment- the enchantment to checkmodifier- 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
-