Class DamageRequest

java.lang.Object
studio.magemonkey.codex.api.damage.DamageRequest

public final class DamageRequest extends Object
A description of a hit, written by the plugin that deals it and read by the plugin that calculates it.

Without a request, a plugin handling an EntityDamageEvent can only guess what a call to damage() was meant to be. A request states it up front. It is handed over through DamageContexts.

A request is immutable. Build one with builder().

  • Method Details

    • builder

      @NotNull public static DamageRequest.Builder builder()
    • hasKnockback

      public boolean hasKnockback()
      Returns:
      whether the hit should knock the target back
    • getWeaponScale

      public double getWeaponScale(@NotNull String type)
      Parameters:
      type - a damage type id of the plugin that calculates the damage, without a namespace
      Returns:
      what the weapon's damage of that type is multiplied by
    • getWeaponBonus

      public double getWeaponBonus(@NotNull String type)
      Parameters:
      type - a damage type id of the plugin that calculates the damage, without a namespace
      Returns:
      what is added to the weapon's damage of that type
    • adjustsWeaponDamage

      public boolean adjustsWeaponDamage()
      Returns:
      whether this request changes the weapon's damage at all
    • adjustWeaponDamage

      public double adjustWeaponDamage(@NotNull String type, double amount)
      Applies this request's scale and bonus to one damage type of the attacker's weapon: the amount is multiplied by the scale, then the bonus is added.

      A type the weapon does not deal stays at 0, so a bonus never gives a weapon a damage type it does not have. The result can be negative when the bonus is; what to do with that is up to the caller.

      This only means something where the weapon's damage is part of the hit, which is WeaponStatsMode.ADD.

      Parameters:
      type - the damage type id, without a namespace
      amount - the weapon's damage of that type
      Returns:
      the adjusted amount
    • getTotal

      public double getTotal()
      Returns:
      the sum of all amounts
    • getOrigin

      @NotNull public DamageOrigin getOrigin()
      What kind of thing deals the damage.
    • getSource

      @Nullable public org.bukkit.entity.LivingEntity getSource()
      The entity the damage is attributed to, or null if there is none.
    • getCause

      @Nullable public org.bukkit.event.entity.EntityDamageEvent.DamageCause getCause()
      The cause the dealer wants the damage to have, or null to leave it as Bukkit reports it.
    • getAmounts

      @NotNull public Map<String,Double> getAmounts()
      The damage of the hit, by damage type, in the order the amounts were added. The map cannot be changed.

      A type is the id the dealer used, exactly as given. It may carry a provider's namespace (DIVINITY_fire) or be a plain classification (default).

    • getWeaponStats

      @NotNull public WeaponStatsMode getWeaponStats()
      How the attacker's equipment should take part in the hit.
    • getWeaponScale

      public double getWeaponScale()
      What every damage type of the attacker's weapon is multiplied by, unless a type has its own factor. 1 leaves the weapon's damage as it is. See adjustWeaponDamage(String, double).
    • getWeaponBonus

      public double getWeaponBonus()
      What is added to every damage type of the attacker's weapon, unless a type has its own amount. It may be negative. See adjustWeaponDamage(String, double).
    • toString

      public String toString()
      Overrides:
      toString in class Object