English
Damage Event API
EmakiAttributeDamageEvent is a cancellable Bukkit event. It fires on the main thread synchronously during damage resolution, after EmakiAttribute finishes calculating attribute damage and before the damage is applied. Listeners can cancel, modify, or record the damage inside the callback
The event class is provided by the public API module EmakiAttributeApi as emaki.jiuwu.craft.attribute.api.event.EmakiAttributeDamageEvent; the related model classes DamageContext, DamageContextVariables, and DamageResult live in emaki.jiuwu.craft.attribute.api.model
Event behavior
- It is cancellable. If cancelled, no damage is applied
- The final damage can be changed with
setFinalDamage; setting it to0or lower also suppresses the hit - 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() | Projectile | Projectile entity; null for melee |
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);
}DamageResult fields
DamageResult is an immutable record obtained from getDamageResult():
| Method | Return | Description |
|---|---|---|
damageTypeId() | String | Resolved damage type id |
finalDamage() | double | Final damage from the pipeline; clamped to be non-negative |
critical() | boolean | Whether the hit resolved as critical |
roll() | double | Random roll used during resolution |
stageValues() | Map<String, Double> | Per-stage result keyed by stage id |
damageContext() | DamageContext | Context the result was computed from |
variables() | DamageContextVariables | Control variables carried by the context |
context() | Map<String, Object> | Control variables as a plain map |
DamageContextVariables control flags
DamageContextVariables normalizes its keys, and boolean lookups accept true/false, yes/no, and 1/0 (case-insensitive). The following flags are read by damage resolution and the MythicMobs mechanics; equivalent aliases are shown in parentheses:
| Flag | Default | Description |
|---|---|---|
allow_critical (critical) | true | Whether critical rolls are allowed |
allow_target_dodge (target_dodge, allow_dodge, dodge) | false | Whether the target may dodge |
calculate_target_defense (target_defense, calculate_defense, defense) | true | Whether target defense is calculated |
trigger_mythic_on_damaged (trigger_on_damaged, mythic_on_damaged) | false | Whether the MythicMobs on_damaged event fires |
Common accessors: get(key), string(key, fallback), doubleValue(key, fallback), getBoolean(fallback, keys...), contains(key), asMap()
Read-only combat facts
The variables below are written by Attribute for damage stage expressions and listeners to read. They are not control flags:
| Variable | Description |
|---|---|
target_blocking | Whether this hit counts as a valid raised shield (including the facing check), 1 or 0. It can be 1 only under shield.mode: attribute; under any other configuration it is always 0. See "Shield blocking" in Damage System |
Notes
- Firing thread: the event fires on the main thread during damage resolution
setFinalDamagedirectly changes the value that will be applied; later stages no longer run- Cancelling the event, or setting final damage to
0or lower, makes EmakiAttribute skip this hit entirely