程序包 org.bukkit.damage

# 接口 DamageSource

@Experimental public interface DamageSource
Represents a source of damage.

- ## 嵌套类概要

  嵌套类
  修饰符和类型
  接口
  说明
  `static interface`
  `DamageSource.Builder`
  Utility class to make building a `DamageSource` easier.

- ## 方法概要

  修饰符和类型
  方法
  说明
  `static @NotNull DamageSource.Builder`
  `builder(@NotNull DamageType damageType)`
  Create a new `DamageSource.Builder`.
  `@Nullable Entity`
  `getCausingEntity()`
  Get the `Entity` that caused the damage to occur.
  `@Nullable Location`
  `getDamageLocation()`
  Get the `Location` from where the damage originated.
  `@NotNull DamageType`
  `getDamageType()`
  Get the `DamageType`.
  `@Nullable Entity`
  `getDirectEntity()`
  Get the `Entity` that directly caused the damage.
  `float`
  `getFoodExhaustion()`
  Get the amount of hunger exhaustion caused by this damage.
  `@Nullable Location`
  `getSourceLocation()`
  Get the `Location` from where the damage originated.
  `boolean`
  `isIndirect()`
  Get if this damage is indirect.
  `boolean`
  `scalesWithDifficulty()`
  Gets if this source of damage scales with difficulty.

- ## 方法详细资料

  - ### getDamageType

    @NotNull @NotNull DamageType getDamageType()
    Get the `DamageType`.
    返回:
      the damage type

  - ### getCausingEntity

    @Nullable @Nullable Entity getCausingEntity()
    Get the `Entity` that caused the damage to occur.

    Not to be confused with `getDirectEntity()`, the causing entity is the entity to which the damage is ultimately attributed if the receiver is killed. If, for example, the receiver was damaged by a projectile, the shooter/thrower would be returned.

    返回:
      an Entity or null

  - ### getDirectEntity

    @Nullable @Nullable Entity getDirectEntity()
    Get the `Entity` that directly caused the damage.

    Not to be confused with `getCausingEntity()`, the direct entity is the entity that actually inflicted the damage. If, for example, the receiver was damaged by a projectile, the projectile would be returned.

    返回:
      an Entity or null

  - ### getDamageLocation

    @Nullable @Nullable Location getDamageLocation()
    Get the `Location` from where the damage originated. This will only be present if an entity did not cause the damage.
    返回:
      the location, or null if none

  - ### getSourceLocation

    @Nullable @Nullable Location getSourceLocation()
    Get the `Location` from where the damage originated.

    This is a convenience method to get the final location of the damage. This method will attempt to return `the damage location`. If this is null, the `causing entity location` will be returned. Finally if there is no damage location nor a causing entity, null will be returned.

    返回:
      the source of the location or null.

  - ### isIndirect

    boolean isIndirect()
    Get if this damage is indirect.

    Damage is considered indirect if `getCausingEntity()` is not equal to `getDirectEntity()`. This will be the case, for example, if a skeleton shot an arrow or a player threw a potion.

    返回:
      `true` if is indirect, `false` otherwise.

  - ### getFoodExhaustion

    float getFoodExhaustion()
    Get the amount of hunger exhaustion caused by this damage.
    返回:
      the amount of hunger exhaustion caused.

  - ### scalesWithDifficulty

    boolean scalesWithDifficulty()
    Gets if this source of damage scales with difficulty.
    返回:
      `True` if scales.

  - ### builder

    @NotNull static @NotNull DamageSource.Builder builder(@NotNull @NotNull DamageType damageType)
    Create a new `DamageSource.Builder`.
    参数:
      `damageType` - the `DamageType` to use
    返回:
      a `DamageSource.Builder`