Damage Event API
EmakiAttributeDamageEvent is a Bukkit event fired after EmakiAttribute finishes calculating attribute damage and before the damage is applied. External plugins can listen to it to cancel, modify, or record damage.
Event behavior
- It is cancellable. If cancelled, no damage is applied.
- The final damage can be changed with
setFinalDamage. - Projectile damage also fires this event; use
getProjectile()to check the projectile entity.
Main methods
| Method | Return | Description |
|---|---|---|
getAttacker() | LivingEntity | Attacker, may be null for environmental damage. |
getTarget() | LivingEntity | Target entity. |
getProjectile() | Entity | Projectile entity, may be null. |
getDamageTypeId() | String | Damage type id, such as physical or spell. |
getBaseDamage() | double | Base damage before full calculation. |
isCritical() | boolean | Whether the hit is critical. |
getRoll() | double | Critical roll value. |
getFinalDamage() | double | Final calculated damage. |
setFinalDamage(double) | void | Replace final damage. |
getCause() | DamageCause | Bukkit damage cause. |
getDamageContext() | DamageContext | Full damage context. |
getDamageResult() | DamageResult | Full calculation result including stage values. |
getVariables() | DamageContextVariables | Context control flags. |
getContext() | Map<String, Object> | Context data map. |
isCancelled() | boolean | Whether the event is cancelled. |
setCancelled(boolean) | void | Cancel or restore the event. |
Example
java
@EventHandler
public void onAttributeDamage(EmakiAttributeDamageEvent event) {
event.setFinalDamage(event.getFinalDamage() * 0.9);
if (event.isCritical()) {
event.setCancelled(true);
}
Map<String, Double> stages = event.getDamageResult().stageValues();
double defenseReduction = stages.getOrDefault("target_defense", 0.0);
}Notes
- The event is fired on the main thread.
setFinalDamagedirectly changes the value that will be applied.- If cancelled, the target receives no damage and no hit feedback from this event path.