Interface DamageSourceAdapter


public interface DamageSourceAdapter
Access to Bukkit's damage sources, which exist from Minecraft 1.20.4. Use it through DamageSources, which picks the implementation that fits the running server.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    damage(org.bukkit.entity.Damageable target, double amount, org.bukkit.event.entity.EntityDamageEvent.DamageCause cause, org.bukkit.entity.Entity source)
    Damages the target with a real damage source, so that the damage event carries the wanted cause and the death message fits it.
    org.bukkit.entity.Entity
    getCausingEntity(org.bukkit.event.entity.EntityDamageEvent event)
    The entity responsible for the damage: the shooter of an arrow, the attacker of a melee hit.
    getDamageType(org.bukkit.event.entity.EntityDamageEvent event)
     
    org.bukkit.entity.Entity
    getDirectEntity(org.bukkit.event.entity.EntityDamageEvent event)
    The entity that touched the victim: the arrow of a bow shot, the attacker of a melee hit.
    boolean
     
  • Method Details

    • isSupported

      boolean isSupported()
      Returns:
      whether the server has damage sources at all
    • damage

      boolean damage(@NotNull org.bukkit.entity.Damageable target, double amount, @NotNull org.bukkit.event.entity.EntityDamageEvent.DamageCause cause, @Nullable org.bukkit.entity.Entity source)
      Damages the target with a real damage source, so that the damage event carries the wanted cause and the death message fits it.

      The cause is translated to the vanilla damage type closest to it. That type brings its vanilla rules along: damage of a fire type does nothing to a target with fire resistance, for example.

      Parameters:
      target - the entity to damage
      amount - the amount of damage
      cause - the cause the damage should have
      source - the entity the damage is attributed to, or null
      Returns:
      true if the damage call was made. False if the server has no damage sources or the cause has no matching damage type; nothing was done then, and the caller should deal the damage another way
    • getDamageType

      @Nullable String getDamageType(@NotNull org.bukkit.event.entity.EntityDamageEvent event)
      Returns:
      the key of the event's vanilla damage type, such as minecraft:thorns, or null if the server has no damage sources
    • getDirectEntity

      @Nullable org.bukkit.entity.Entity getDirectEntity(@NotNull org.bukkit.event.entity.EntityDamageEvent event)
      The entity that touched the victim: the arrow of a bow shot, the attacker of a melee hit.
      Returns:
      the direct entity, or null if no entity was involved
    • getCausingEntity

      @Nullable org.bukkit.entity.Entity getCausingEntity(@NotNull org.bukkit.event.entity.EntityDamageEvent event)
      The entity responsible for the damage: the shooter of an arrow, the attacker of a melee hit.
      Returns:
      the causing entity, or null if no entity was involved