Class AttributeModifierHelper
java.lang.Object
io.artificial.enchantments.internal.AttributeModifierHelper
Helper for managing attribute modifiers on entities and items.
Provides pure functions for adding/removing attribute modifiers with proper UUID tracking. All operations are thread-safe and idempotent where possible.
Common attributes:
- ATTACK_DAMAGE - Melee damage
- ATTACK_SPEED - Attack cooldown speed
- ARMOR - Damage reduction
- ARMOR_TOUGHNESS - Armor effectiveness
- MAX_HEALTH - Maximum health
- MOVEMENT_SPEED - Movement speed
- KNOCKBACK_RESISTANCE - Knockback reduction
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaddItemModifier(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.attribute.Attribute attribute, @NotNull UUID uuid, double amount, org.bukkit.attribute.AttributeModifier.Operation operation, @Nullable org.bukkit.inventory.EquipmentSlot slot) Adds an attribute modifier to an item stack.static booleanaddModifier(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull org.bukkit.attribute.Attribute attribute, @NotNull UUID uuid, double amount, org.bukkit.attribute.AttributeModifier.Operation operation) Adds a temporary attribute modifier to a living entity.static booleanapplyArmorBonus(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull String enchantmentKey, double armorBonus) Applies armor bonus modifier to an entity.static booleanapplyAttackSpeedBonus(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull String enchantmentKey, double speedBonus) Applies attack speed modifier to an entity.static booleanapplyDamageBonus(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull String enchantmentKey, double damageBonus) Applies attack damage modifier to an entity.static booleanapplyMovementSpeedBonus(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull String enchantmentKey, double speedMultiplier) Applies movement speed modifier to an entity.static @NotNull UUIDarmorModifierUuid(@NotNull String enchantmentKey) Creates a modifier UUID for armor modifiers.static @NotNull UUIDattackSpeedModifierUuid(@NotNull String enchantmentKey) Creates a modifier UUID for attack speed modifiers.static @NotNull UUIDdamageModifierUuid(@NotNull String enchantmentKey) Creates a modifier UUID for damage modifiers.static @NotNull UUIDgenerateModifierUuid(@NotNull String enchantmentKey, @NotNull String target) Generates a unique UUID for attribute modifiers.getActiveModifiers(@NotNull org.bukkit.entity.LivingEntity entity) Gets all active modifiers created by this helper on an entity.static doublegetBaseValue(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull org.bukkit.attribute.Attribute attribute) Gets the base value of an attribute without modifiers.static doublegetTotalValue(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull org.bukkit.attribute.Attribute attribute) Gets the total value of an attribute including all modifiers.static @NotNull UUIDmovementSpeedModifierUuid(@NotNull String enchantmentKey) Creates a modifier UUID for movement speed modifiers.static intremoveAllModifiers(@NotNull org.bukkit.entity.LivingEntity entity) Removes all modifiers created by this helper from an entity.static booleanremoveItemModifier(@NotNull org.bukkit.inventory.ItemStack item, @NotNull org.bukkit.attribute.Attribute attribute, @NotNull UUID uuid) Removes an attribute modifier from an item stack.static booleanremoveModifier(@NotNull org.bukkit.entity.LivingEntity entity, @NotNull org.bukkit.attribute.Attribute attribute, @NotNull UUID uuid) Removes an attribute modifier by UUID.
-
Method Details
-
addModifier
public static boolean addModifier(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull org.bukkit.attribute.Attribute attribute, @NotNull @NotNull UUID uuid, double amount, @NotNull org.bukkit.attribute.AttributeModifier.Operation operation) Adds a temporary attribute modifier to a living entity.If a modifier with the same UUID already exists, it will be removed and replaced with the new value.
- Parameters:
entity- the entity to modifyattribute- the attribute to modifyuuid- unique identifier for this modifier (for tracking/removal)amount- the amount to addoperation- the operation type (ADD_NUMBER, ADD_SCALAR, MULTIPLY_SCALAR_1)- Returns:
- true if the modifier was applied successfully
-
removeModifier
public static boolean removeModifier(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull org.bukkit.attribute.Attribute attribute, @NotNull @NotNull UUID uuid) Removes an attribute modifier by UUID.- Parameters:
entity- the entity to modifyattribute- the attribute to modifyuuid- the UUID of the modifier to remove- Returns:
- true if a modifier was found and removed
-
removeAllModifiers
public static int removeAllModifiers(@NotNull @NotNull org.bukkit.entity.LivingEntity entity) Removes all modifiers created by this helper from an entity.Only removes modifiers whose names start with "artificial_enchantment_"
- Parameters:
entity- the entity to clean up- Returns:
- number of modifiers removed
-
getTotalValue
public static double getTotalValue(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull org.bukkit.attribute.Attribute attribute) Gets the total value of an attribute including all modifiers.- Parameters:
entity- the entity to checkattribute- the attribute to check- Returns:
- the total attribute value, or 0 if the entity doesn't have the attribute
-
getBaseValue
public static double getBaseValue(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull org.bukkit.attribute.Attribute attribute) Gets the base value of an attribute without modifiers.- Parameters:
entity- the entity to checkattribute- the attribute to check- Returns:
- the base attribute value, or 0 if the entity doesn't have the attribute
-
addItemModifier
public static boolean addItemModifier(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.attribute.Attribute attribute, @NotNull @NotNull UUID uuid, double amount, @NotNull org.bukkit.attribute.AttributeModifier.Operation operation, @Nullable @Nullable org.bukkit.inventory.EquipmentSlot slot) Adds an attribute modifier to an item stack.Item modifiers persist when the item is held/worn in the specified slot.
- Parameters:
item- the item to modifyattribute- the attribute to modifyuuid- unique identifier for this modifieramount- the amount to addoperation- the operation typeslot- the equipment slot this modifier applies to- Returns:
- true if the modifier was applied
-
removeItemModifier
public static boolean removeItemModifier(@NotNull @NotNull org.bukkit.inventory.ItemStack item, @NotNull @NotNull org.bukkit.attribute.Attribute attribute, @NotNull @NotNull UUID uuid) Removes an attribute modifier from an item stack.- Parameters:
item- the item to modifyattribute- the attribute to modifyuuid- the UUID of the modifier to remove- Returns:
- true if a modifier was found and removed
-
generateModifierUuid
@NotNull public static @NotNull UUID generateModifierUuid(@NotNull @NotNull String enchantmentKey, @NotNull @NotNull String target) Generates a unique UUID for attribute modifiers.The UUID is derived from the enchantment key and target to ensure consistent IDs across server restarts.
- Parameters:
enchantmentKey- the enchantment identifiertarget- the target attribute or context- Returns:
- a deterministic UUID for the modifier
-
damageModifierUuid
Creates a modifier UUID for damage modifiers.- Parameters:
enchantmentKey- the enchantment identifier- Returns:
- a deterministic UUID for damage modifiers
-
attackSpeedModifierUuid
@NotNull public static @NotNull UUID attackSpeedModifierUuid(@NotNull @NotNull String enchantmentKey) Creates a modifier UUID for attack speed modifiers.- Parameters:
enchantmentKey- the enchantment identifier- Returns:
- a deterministic UUID for attack speed modifiers
-
armorModifierUuid
Creates a modifier UUID for armor modifiers.- Parameters:
enchantmentKey- the enchantment identifier- Returns:
- a deterministic UUID for armor modifiers
-
movementSpeedModifierUuid
@NotNull public static @NotNull UUID movementSpeedModifierUuid(@NotNull @NotNull String enchantmentKey) Creates a modifier UUID for movement speed modifiers.- Parameters:
enchantmentKey- the enchantment identifier- Returns:
- a deterministic UUID for movement speed modifiers
-
applyDamageBonus
public static boolean applyDamageBonus(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull String enchantmentKey, double damageBonus) Applies attack damage modifier to an entity.- Parameters:
entity- the entity to modifyenchantmentKey- the enchantment identifierdamageBonus- the damage amount to add- Returns:
- true if applied successfully
-
applyAttackSpeedBonus
public static boolean applyAttackSpeedBonus(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull String enchantmentKey, double speedBonus) Applies attack speed modifier to an entity.- Parameters:
entity- the entity to modifyenchantmentKey- the enchantment identifierspeedBonus- the speed amount to add (negative for slower)- Returns:
- true if applied successfully
-
applyArmorBonus
public static boolean applyArmorBonus(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull String enchantmentKey, double armorBonus) Applies armor bonus modifier to an entity.- Parameters:
entity- the entity to modifyenchantmentKey- the enchantment identifierarmorBonus- the armor amount to add- Returns:
- true if applied successfully
-
applyMovementSpeedBonus
public static boolean applyMovementSpeedBonus(@NotNull @NotNull org.bukkit.entity.LivingEntity entity, @NotNull @NotNull String enchantmentKey, double speedMultiplier) Applies movement speed modifier to an entity.- Parameters:
entity- the entity to modifyenchantmentKey- the enchantment identifierspeedMultiplier- the speed multiplier (e.g., 0.1 for +10%)- Returns:
- true if applied successfully
-
getActiveModifiers
@NotNull public static @NotNull Map<org.bukkit.attribute.Attribute,List<UUID>> getActiveModifiers(@NotNull @NotNull org.bukkit.entity.LivingEntity entity) Gets all active modifiers created by this helper on an entity.- Parameters:
entity- the entity to check- Returns:
- map of attribute to list of modifier UUIDs
-