Skip to content

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 to 0 or lower also suppresses the hit.
  • Projectile damage also fires this event; use getProjectile() to check the projectile entity.

Main methods

MethodReturnDescription
getAttacker()LivingEntityAttacker, may be null for environmental damage.
getTarget()LivingEntityTarget entity.
getProjectile()ProjectileProjectile entity; null for melee.
getDamageTypeId()StringDamage type id, such as physical or spell.
getBaseDamage()doubleBase damage before full calculation.
isCritical()booleanWhether the hit is critical.
getRoll()doubleCritical roll value.
getFinalDamage()doubleFinal calculated damage.
setFinalDamage(double)voidReplace final damage.
getCause()DamageCauseBukkit damage cause.
getDamageContext()DamageContextFull damage context.
getDamageResult()DamageResultFull calculation result including stage values.
getVariables()DamageContextVariablesContext control flags.
getContext()Map<String, Object>Context data map.
isCancelled()booleanWhether the event is cancelled.
setCancelled(boolean)voidCancel 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():

MethodReturnDescription
damageTypeId()StringResolved damage type id.
finalDamage()doubleFinal damage from the pipeline; clamped to be non-negative.
critical()booleanWhether the hit resolved as critical.
roll()doubleRandom roll used during resolution.
stageValues()Map<String, Double>Per-stage result keyed by stage id.
damageContext()DamageContextContext the result was computed from.
variables()DamageContextVariablesControl 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:

FlagDefaultDescription
allow_critical (critical)trueWhether critical rolls are allowed.
allow_target_dodge (target_dodge, allow_dodge, dodge)falseWhether the target may dodge.
calculate_target_defense (target_defense, calculate_defense, defense)trueWhether target defense is calculated.
trigger_mythic_on_damaged (trigger_on_damaged, mythic_on_damaged)falseWhether 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.
  • setFinalDamage directly changes the value that will be applied; later stages no longer run.
  • Cancelling the event, or setting final damage to 0 or lower, makes EmakiAttribute skip this hit entirely.