Class FinalDamageFallback

java.lang.Object
studio.magemonkey.codex.api.damage.FinalDamageFallback
All Implemented Interfaces:
org.bukkit.event.Listener

public final class FinalDamageFallback extends Object implements org.bukkit.event.Listener
Fires FinalDamageEvent for every hit on a living entity that no provider fires it for, so that consumers always listen to that one event and never ask whether a provider is present.

Codex registers this listener when it enables. It listens to EntityDamageEvent at EventPriority.HIGHEST, ignoring cancelled events, and for each hit:

  1. does nothing if FinalDamageEvent.willFire(EntityDamageEvent) says a provider will fire the event, or if the target is not a LivingEntity;
  2. otherwise fires a FinalDamageEvent whose only damage type is FinalDamageEvent.DEFAULT_TYPE, holding EntityDamageEvent.getDamage();
  3. afterwards cancels the Bukkit event if the FinalDamageEvent was cancelled, or else sets the Bukkit damage to the new total, but only if the total changed. An untouched hit leaves the Bukkit event alone, so its vanilla damage modifiers stay as they are.
The request comes from DamageContexts.peek(EntityDamageEvent), never claim: the fallback only reads it, and leaves it to whoever calculates the hit.

What the fallback fires for

  • WeaponStatsMode.RAW requests still fire. RAW asks the calculating plugin not to bring the attacker's weapon stats into the hit. It does not hide the hit from consumers: without a provider, skill plugins such as Fabled have always seen these hits and run their triggers on them, and they keep doing so. A consumer that wants to leave RAW hits alone checks FinalDamageEvent.getWeaponStatsMode().
  • Hits of 0 damage or less, and fake damage events (such as those a plugin fires only to ask whether an attack would be allowed) are not filtered out. Consumers filter what they do not want.
  • Constructor Details

    • FinalDamageFallback

      public FinalDamageFallback(@NotNull org.bukkit.plugin.PluginManager pluginManager)
      Parameters:
      pluginManager - the plugin manager the FinalDamageEvent is called through
  • Method Details

    • onDamage

      public void onDamage(@NotNull org.bukkit.event.entity.EntityDamageEvent event)
      Fires FinalDamageEvent for the hit unless a provider will. See the class description.
      Parameters:
      event - the Bukkit damage event