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.
The event class is provided by the public API module EmakiAttributeApi as emaki.jiuwu.craft.attribute.api.EmakiAttributeDamageEvent; the related model classes DamageContext, DamageContextVariables, and DamageResult live in emaki.jiuwu.craft.attribute.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
@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().
Notes
- The event is fired 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.