Class AbstractDamageEntityEvent
java.lang.Object
org.spongepowered.api.event.impl.AbstractEvent
org.spongepowered.api.event.impl.entity.AbstractModifierEvent<DamageFunction,DamageModifier>
org.spongepowered.api.event.impl.entity.AbstractDamageEntityEvent
- All Implemented Interfaces:
Cancellable
,DamageEntityEvent
,Event
public abstract class AbstractDamageEntityEvent
extends AbstractModifierEvent<DamageFunction,DamageModifier>
implements DamageEntityEvent
-
Field Summary
Modifier and TypeFieldDescriptionprotected double
protected double
protected List<DamageFunction>
Fields inherited from class org.spongepowered.api.event.impl.entity.AbstractModifierEvent
modifierFunctions, modifiers, originalFinalAmount, originalModifierMap, originalModifiers
Fields inherited from class org.spongepowered.api.event.impl.AbstractEvent
currentOrder
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDamageModifierBefore
(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> before) Adds the providedDamageModifier
andDoubleUnaryOperator
to the list of modifiers, such that theSet
containingDamageModifierType
s provided inbefore
will appear after the provided damage modifier.void
addModifierAfter
(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> after) Adds the providedDamageModifier
andDoubleUnaryOperator
to the list of modifiers, such that the modifier will appear in order after any current modifiers whose type are included in the providedSet
ofDamageModifierType
s.double
Gets the "base" damage to deal to the targetedEntity
.protected DamageFunction
convertTuple
(DamageModifier obj, DoubleUnaryOperator function) final double
damage
(DamageModifier damageModifier) Gets the damage for the providedDamageModifier
.final double
Gets the final damage that will be passed into the proceedingDamageEntityEvent
.protected final void
init()
Called once all fields have been set by the generated constructor in a subclass.final boolean
isModifierApplicable
(DamageModifier damageModifier) Checks whether the providedDamageModifier
is applicable to the current availableDamageModifier
s.Gets the modifiers affecting this event.final Map<DamageModifier,
Double> Gets an immutableMap
of all originalDamageModifier
s and their associated "modified" damage.final double
Gets the original "final" amount of damage after all originalDamageModifier
s are applied toDamageEntityEvent.originalDamage()
.final double
originalModifierDamage
(DamageModifier damageModifier) Gets the original damage for the providedDamageModifier
.final void
setBaseDamage
(double baseDamage) Sets the "base" damage to deal to the targetedEntity
.final void
setDamage
(DamageModifier damageModifier, DoubleUnaryOperator function) Sets the providedDamageFunction
to be used for the givenDamageModifier
.boolean
Returns whether or not this event will cause the entity to die if the event is not cancelled.Methods inherited from class org.spongepowered.api.event.impl.entity.AbstractModifierEvent
finalAmount, init, recalculateDamages
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.spongepowered.api.event.Cancellable
isCancelled, setCancelled
Methods inherited from interface org.spongepowered.api.event.entity.DamageEntityEvent
entity, originalDamage, originalFunctions
-
Field Details
-
originalDamage
protected double originalDamage -
originalFunctions
-
baseDamage
protected double baseDamage
-
-
Constructor Details
-
AbstractDamageEntityEvent
public AbstractDamageEntityEvent()
-
-
Method Details
-
init
protected final void init()Description copied from class:AbstractEvent
Called once all fields have been set by the generated constructor in a subclass.This method should be used to initialize any fields that depend on parameters passed to the constructor.
- Overrides:
init
in classAbstractEvent
-
originalModifierDamage
Description copied from interface:DamageEntityEvent
Gets the original damage for the providedDamageModifier
. If the providedDamageModifier
was not included inDamageEntityEvent.originalDamages()
, anIllegalArgumentException
is thrown.- Specified by:
originalModifierDamage
in interfaceDamageEntityEvent
- Parameters:
damageModifier
- The original damage modifier- Returns:
- The original damage change
-
originalFinalDamage
public final double originalFinalDamage()Description copied from interface:DamageEntityEvent
Gets the original "final" amount of damage after all originalDamageModifier
s are applied toDamageEntityEvent.originalDamage()
. The "final" damage is considered the amount of health being lost by theEntity
, if health is tracked.- Specified by:
originalFinalDamage
in interfaceDamageEntityEvent
- Returns:
- The final amount of damage to originally deal
-
originalDamages
Description copied from interface:DamageEntityEvent
Gets an immutableMap
of all originalDamageModifier
s and their associated "modified" damage. Note that ordering is not retained.- Specified by:
originalDamages
in interfaceDamageEntityEvent
- Returns:
- An immutable map of the original modified damages
-
finalDamage
public final double finalDamage()Description copied from interface:DamageEntityEvent
Gets the final damage that will be passed into the proceedingDamageEntityEvent
. The final damage is the end result of theDamageEntityEvent.baseDamage()
being applied inDoubleUnaryOperator.applyAsDouble(double)
available from all theTuple
s ofDamageModifier
toDamageFunction
inDamageEntityEvent.originalFunctions()
.- Specified by:
finalDamage
in interfaceDamageEntityEvent
- Returns:
- The final damage to deal
-
isModifierApplicable
Description copied from interface:DamageEntityEvent
Checks whether the providedDamageModifier
is applicable to the current availableDamageModifier
s.- Specified by:
isModifierApplicable
in interfaceDamageEntityEvent
- Parameters:
damageModifier
- The damage modifier to check- Returns:
- True if the damage modifier is relevant to this event
-
damage
Description copied from interface:DamageEntityEvent
Gets the damage for the providedDamageModifier
. Providing thatDamageEntityEvent.isModifierApplicable(DamageModifier)
returnstrue
, the cached "damage" for theDamageModifier
is returned.- Specified by:
damage
in interfaceDamageEntityEvent
- Parameters:
damageModifier
- The damage modifier to get the damage for- Returns:
- The modifier
-
setDamage
Description copied from interface:DamageEntityEvent
Sets the providedDamageFunction
to be used for the givenDamageModifier
. If theDamageModifier
is already included inDamageEntityEvent.modifiers()
, theDoubleUnaryOperator
replaces the existing function. If there is noTuple
for theDamageModifier
, a new one is created and added to the end of the list ofDoubleUnaryOperator
s to be applied to theDamageEntityEvent.baseDamage()
.If needing to create a custom
DamageModifier
is required, usage of theDamageModifier.Builder
is recommended.- Specified by:
setDamage
in interfaceDamageEntityEvent
- Parameters:
damageModifier
- The damage modifierfunction
- The function to map to the modifier
-
addDamageModifierBefore
public void addDamageModifierBefore(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> before) Description copied from interface:DamageEntityEvent
Adds the providedDamageModifier
andDoubleUnaryOperator
to the list of modifiers, such that theSet
containingDamageModifierType
s provided inbefore
will appear after the provided damage modifier.- Specified by:
addDamageModifierBefore
in interfaceDamageEntityEvent
- Parameters:
damageModifier
- The damage modifier to addfunction
- The associated functionbefore
- The set containing the modifier types to come after the provided modifier
-
addModifierAfter
public void addModifierAfter(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> after) Description copied from interface:DamageEntityEvent
Adds the providedDamageModifier
andDoubleUnaryOperator
to the list of modifiers, such that the modifier will appear in order after any current modifiers whose type are included in the providedSet
ofDamageModifierType
s.- Specified by:
addModifierAfter
in interfaceDamageEntityEvent
- Parameters:
damageModifier
- The damage modifier to addfunction
- The associated functionafter
- The set of modifier types to come before the new modifier
-
convertTuple
- Specified by:
convertTuple
in classAbstractModifierEvent<DamageFunction,
DamageModifier>
-
modifiers
Description copied from class:AbstractModifierEvent
Gets the modifiers affecting this event.- Specified by:
modifiers
in interfaceDamageEntityEvent
- Overrides:
modifiers
in classAbstractModifierEvent<DamageFunction,
DamageModifier> - Returns:
- The list of modifiers
-
baseDamage
public double baseDamage()Description copied from interface:DamageEntityEvent
Gets the "base" damage to deal to the targetedEntity
. The "base" damage is the original value before passing along the chain ofDamageFunction
s for all knownDamageModifier
s.- Specified by:
baseDamage
in interfaceDamageEntityEvent
- Returns:
- The base damage
-
setBaseDamage
public final void setBaseDamage(double baseDamage) Description copied from interface:DamageEntityEvent
Sets the "base" damage to deal to the targetedEntity
. The "base" damage is the original value before passing along the chain ofDamageFunction
s for all knownDamageModifier
s.- Specified by:
setBaseDamage
in interfaceDamageEntityEvent
- Parameters:
baseDamage
- The base damage
-
willCauseDeath
public boolean willCauseDeath()Description copied from interface:DamageEntityEvent
Returns whether or not this event will cause the entity to die if the event is not cancelled. Only supported for living entities, returns false ifDamageEntityEvent.entity()
is not a living entity.- Specified by:
willCauseDeath
in interfaceDamageEntityEvent
- Returns:
- Whether the entity will die
-