Class Damage
java.lang.Object
net.minestom.server.entity.damage.Damage
- All Implemented Interfaces:
Taggable
,TagReadable
,TagWritable
- Direct Known Subclasses:
EntityDamage
,EntityProjectileDamage
,PositionalDamage
Represents a type of damage, required when calling
LivingEntity.damage(Damage)
and retrieved in EntityDamageEvent
.
This class can be extended if you need to include custom fields and/or methods.
-
Constructor Summary
ConstructorDescriptionDamage
(@NotNull DamageType type, @Nullable Entity source, @Nullable Entity attacker, @Nullable Point sourcePosition, float amount) Creates a new damage type. -
Method Summary
Modifier and TypeMethodDescription@Nullable Component
buildDeathMessage
(@NotNull Player killed) Builds the death message linked to this damage type.@Nullable Component
buildDeathScreenText
(@NotNull Player killed) Builds the text sent to a player in his death screen.static @NotNull EntityDamage
fromEntity
(@NotNull Entity entity, float amount) Convenient method to create anEntityDamage
.static @NotNull EntityDamage
fromPlayer
(@NotNull Player player, float amount) Convenient method to create anEntityDamage
.static @NotNull PositionalDamage
fromPosition
(@NotNull DamageType type, @NotNull Point sourcePosition, float amount) static @NotNull Damage
fromProjectile
(@Nullable Entity shooter, @NotNull Entity projectile, float amount) Convenient method to create anEntityProjectileDamage
.float
@Nullable Entity
Gets the "attacker" of the damage.protected SoundEvent
getGenericSound
(@NotNull LivingEntity entity) protected SoundEvent
getPlayerSound
(@NotNull Player player) @Nullable SoundEvent
getSound
(@NotNull LivingEntity entity) Sound event to play when the given entity is hit by this damage.@Nullable Entity
Gets the direct source of the damage.@Nullable Point
Gets the position of the source of the damage, or null if there is none.@NotNull DamageType
getType()
Gets the type of this damage.void
setAmount
(float amount) @NotNull TagHandler
-
Constructor Details
-
Damage
public Damage(@NotNull @NotNull DamageType type, @Nullable @Nullable Entity source, @Nullable @Nullable Entity attacker, @Nullable @Nullable Point sourcePosition, float amount) Creates a new damage type.- Parameters:
type
- the type of this damageamount
- amount of damage
-
-
Method Details
-
getType
Gets the type of this damage.It does not have to be unique to this object.o
- Returns:
- the damage type
-
getAttacker
Gets the "attacker" of the damage. This is the indirect cause of the damage, like the shooter of a projectile, or null if there was none.- Returns:
- the attacker
-
getSource
Gets the direct source of the damage. This is the entity that directly causes the damage, like a projectile, or null if there was none.- Returns:
- the source
-
getSourcePosition
Gets the position of the source of the damage, or null if there is none. This may differ from the source entity's position.- Returns:
- The source position
-
buildDeathMessage
Builds the death message linked to this damage type.Used in
Player.kill()
to broadcast the proper message.- Parameters:
killed
- the player who has been killed- Returns:
- the death message, null to do not send anything
-
fromProjectile
@NotNull public static @NotNull Damage fromProjectile(@Nullable @Nullable Entity shooter, @NotNull @NotNull Entity projectile, float amount) Convenient method to create anEntityProjectileDamage
.- Parameters:
shooter
- the shooterprojectile
- the actual projectileamount
- amount of damage- Returns:
- a new
EntityProjectileDamage
-
fromPlayer
@NotNull public static @NotNull EntityDamage fromPlayer(@NotNull @NotNull Player player, float amount) Convenient method to create anEntityDamage
.- Parameters:
player
- the player damageramount
- amount of damage- Returns:
- a new
EntityDamage
-
fromEntity
@NotNull public static @NotNull EntityDamage fromEntity(@NotNull @NotNull Entity entity, float amount) Convenient method to create anEntityDamage
.- Parameters:
entity
- the entity damageramount
- amount of damage- Returns:
- a new
EntityDamage
-
fromPosition
@NotNull public static @NotNull PositionalDamage fromPosition(@NotNull @NotNull DamageType type, @NotNull @NotNull Point sourcePosition, float amount) -
buildDeathScreenText
Builds the text sent to a player in his death screen.- Parameters:
killed
- the player who has been killed- Returns:
- the death screen text, null to do not send anything
-
getSound
Sound event to play when the given entity is hit by this damage. Possible to return null if no sound should be played- Parameters:
entity
- the entity hit by this damage- Returns:
- the sound to play when the given entity is hurt by this damage type. Can be null if no sound should play
-
getGenericSound
-
getPlayerSound
-
tagHandler
- Specified by:
tagHandler
in interfaceTaggable
-
getAmount
public float getAmount() -
setAmount
public void setAmount(float amount)
-