Class AbstractAttackEntityEvent
- java.lang.Object
-
- org.spongepowered.api.event.impl.AbstractEvent
-
- org.spongepowered.api.event.impl.entity.AbstractModifierEvent<DamageFunction,DamageModifier>
-
- org.spongepowered.api.event.impl.entity.AbstractAttackEntityEvent
-
- All Implemented Interfaces:
Cancellable
,AttackEntityEvent
,Event
public abstract class AbstractAttackEntityEvent extends AbstractModifierEvent<DamageFunction,DamageModifier> implements AttackEntityEvent
-
-
Field Summary
Fields Modifier and Type Field Description protected double
baseDamage
protected double
originalDamage
protected List<DamageFunction>
originalFunctions
-
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
-
Fields inherited from interface org.spongepowered.api.event.entity.AttackEntityEvent
ABSORPTION, BOOTS, CHESTPLATE, CREATOR, GENERAL_ARMOR, HARD_HAT_ARMOR, HELMET, LEGGINGS, NOTIFIER, RESISTANCE, SHIELD, SOURCE
-
-
Constructor Summary
Constructors Constructor Description AbstractAttackEntityEvent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDamageModifierAfter(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> after)
Adds the providedDamageModifier
andFunction
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.void
addDamageModifierBefore(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> before)
Adds the providedDamageModifier
andFunction
to the list of modifiers, such that theSet
containingDamageModifierType
s provided inbefore
will appear after the provided damage modifier.double
baseOutputDamage()
Gets the "base" damage to deal to the targetedEntity
.protected DamageFunction
convertTuple(DamageModifier obj, DoubleUnaryOperator function)
double
finalOutputDamage()
Gets the final damage that will be passed into the proceedingAttackEntityEvent
.protected void
init()
Called once all fields have been set by the generated constructor in a subclass.boolean
isModifierApplicable(DamageModifier damageModifier)
Checks whether the providedDamageModifier
is applicable to the current availableDamageModifier
s.List<DamageFunction>
modifiers()
Gets the modifiers affecting this event.Map<DamageModifier,Double>
originalDamages()
Gets anImmutableMap
of all originalDamageModifier
s and their associated "modified" damage.double
originalFinalDamage()
Gets the original "final" amount of damage after all originalDamageModifier
s are applied toAttackEntityEvent.originalDamage()
.double
originalModifierDamage(DamageModifier damageModifier)
Gets the original damage for the providedDamageModifier
.double
outputDamage(DamageModifier damageModifier)
Gets the damage for the providedDamageModifier
.void
setBaseOutputDamage(double baseDamage)
Sets the "base" damage to deal to the targetedEntity
.void
setOutputDamage(DamageModifier damageModifier, DoubleUnaryOperator function)
Sets the providedFunction
to be used for the givenDamageModifier
.-
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.entity.AttackEntityEvent
entity, knockbackModifier, originalDamage, originalFunctions, setKnockbackModifier
-
Methods inherited from interface org.spongepowered.api.event.Cancellable
isCancelled, setCancelled
-
-
-
-
Field Detail
-
originalDamage
protected double originalDamage
-
originalFunctions
protected List<DamageFunction> originalFunctions
-
baseDamage
protected double baseDamage
-
-
Method Detail
-
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
public final double originalModifierDamage(DamageModifier damageModifier)
Description copied from interface:AttackEntityEvent
Gets the original damage for the providedDamageModifier
. If the providedDamageModifier
was not included inAttackEntityEvent.originalDamages()
, anIllegalArgumentException
is thrown.- Specified by:
originalModifierDamage
in interfaceAttackEntityEvent
- Parameters:
damageModifier
- The original damage modifier- Returns:
- The original damage change
-
originalFinalDamage
public final double originalFinalDamage()
Description copied from interface:AttackEntityEvent
Gets the original "final" amount of damage after all originalDamageModifier
s are applied toAttackEntityEvent.originalDamage()
. The "final" damage is considered the amount of health being lost by theEntity
, if health is tracked.- Specified by:
originalFinalDamage
in interfaceAttackEntityEvent
- Returns:
- The final amount of damage to originally deal
-
originalDamages
public final Map<DamageModifier,Double> originalDamages()
Description copied from interface:AttackEntityEvent
Gets anImmutableMap
of all originalDamageModifier
s and their associated "modified" damage. Note that ordering is not retained.- Specified by:
originalDamages
in interfaceAttackEntityEvent
- Returns:
- An immutable map of the original modified damages
-
finalOutputDamage
public final double finalOutputDamage()
Description copied from interface:AttackEntityEvent
Gets the final damage that will be passed into the proceedingAttackEntityEvent
. The final damage is the end result of theAttackEntityEvent.baseOutputDamage()
being applied inFunction.apply(Object)
available from all theTuple
s ofDamageModifier
toFunction
inAttackEntityEvent.originalFunctions()
.- Specified by:
finalOutputDamage
in interfaceAttackEntityEvent
- Returns:
- The final damage to deal
-
isModifierApplicable
public final boolean isModifierApplicable(DamageModifier damageModifier)
Description copied from interface:AttackEntityEvent
Checks whether the providedDamageModifier
is applicable to the current availableDamageModifier
s.- Specified by:
isModifierApplicable
in interfaceAttackEntityEvent
- Parameters:
damageModifier
- The damage modifier to check- Returns:
- True if the damage modifier is relevant to this event
-
outputDamage
public final double outputDamage(DamageModifier damageModifier)
Description copied from interface:AttackEntityEvent
Gets the damage for the providedDamageModifier
. Providing thatAttackEntityEvent.isModifierApplicable(DamageModifier)
returnstrue
, the cached "damage" for theDamageModifier
is returned.- Specified by:
outputDamage
in interfaceAttackEntityEvent
- Parameters:
damageModifier
- The damage modifier to get the damage for- Returns:
- The modifier
-
setOutputDamage
public final void setOutputDamage(DamageModifier damageModifier, DoubleUnaryOperator function)
Description copied from interface:AttackEntityEvent
Sets the providedFunction
to be used for the givenDamageModifier
. If theDamageModifier
is already included inAttackEntityEvent.modifiers()
, theFunction
replaces the existing function. If there is noTuple
for theDamageModifier
, a new one is created and added to the end of the list ofFunction
s to be applied to theAttackEntityEvent.baseOutputDamage()
.If needing to create a custom
DamageModifier
is required, usage of theDamageModifier.Builder
is recommended.- Specified by:
setOutputDamage
in interfaceAttackEntityEvent
- 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:AttackEntityEvent
Adds the providedDamageModifier
andFunction
to the list of modifiers, such that theSet
containingDamageModifierType
s provided inbefore
will appear after the provided damage modifier.- Specified by:
addDamageModifierBefore
in interfaceAttackEntityEvent
- Parameters:
damageModifier
- The damage modifier to addfunction
- The associated functionbefore
- The set containing the modifier types to come after the provided modifier
-
addDamageModifierAfter
public void addDamageModifierAfter(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> after)
Description copied from interface:AttackEntityEvent
Adds the providedDamageModifier
andFunction
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:
addDamageModifierAfter
in interfaceAttackEntityEvent
- Parameters:
damageModifier
- The damage modifier to addfunction
- The associated functionafter
- The set of modifier types to come before the new modifier
-
baseOutputDamage
public double baseOutputDamage()
Description copied from interface:AttackEntityEvent
Gets the "base" damage to deal to the targetedEntity
. The "base" damage is the original value before passing along the chain ofFunction
s for all knownDamageModifier
s.- Specified by:
baseOutputDamage
in interfaceAttackEntityEvent
- Returns:
- The base damage
-
setBaseOutputDamage
public final void setBaseOutputDamage(double baseDamage)
Description copied from interface:AttackEntityEvent
Sets the "base" damage to deal to the targetedEntity
. The "base" damage is the original value before passing along the chain ofFunction
s for all knownDamageModifier
s.- Specified by:
setBaseOutputDamage
in interfaceAttackEntityEvent
- Parameters:
baseDamage
- The base damage
-
convertTuple
protected DamageFunction convertTuple(DamageModifier obj, DoubleUnaryOperator function)
- Specified by:
convertTuple
in classAbstractModifierEvent<DamageFunction,DamageModifier>
-
modifiers
public List<DamageFunction> modifiers()
Description copied from class:AbstractModifierEvent
Gets the modifiers affecting this event.- Specified by:
modifiers
in interfaceAttackEntityEvent
- Overrides:
modifiers
in classAbstractModifierEvent<DamageFunction,DamageModifier>
- Returns:
- The list of modifiers
-
-