use of org.spongepowered.api.event.entity.HealEntityEvent in project SpongeAPI by SpongePowered.
the class SpongeAbstractHealEntityEventTest method testModifiersApplicable.
@Test
public void testModifiersApplicable() {
Entity targetEntity = mockParam(Entity.class);
HealthModifier firstModifer = mockParam(HealthModifier.class);
HealthModifier secondModifier = mockParam(HealthModifier.class);
List<HealthFunction> originalFunctions = Lists.newArrayList(HealthFunction.of(firstModifer, p -> p), HealthFunction.of(secondModifier, p -> p));
HealEntityEvent event = SpongeEventFactory.createHealEntityEvent(Cause.of(EventContext.empty(), "none"), originalFunctions, targetEntity, 0);
assertThat(event.isModifierApplicable(firstModifer), is(true));
assertThat(event.isModifierApplicable(secondModifier), is(true));
assertThat(event.isModifierApplicable(mockParam(HealthModifier.class)), is(false));
}
use of org.spongepowered.api.event.entity.HealEntityEvent in project SpongeAPI by SpongePowered.
the class SpongeAbstractHealEntityEventTest method testParams.
@Test
public void testParams() {
Entity targetEntity = mockParam(Entity.class);
int originalDamage = 5;
HealEntityEvent event = SpongeEventFactory.createHealEntityEvent(Cause.of(EventContext.empty(), "none"), Lists.newArrayList(), targetEntity, originalDamage);
assertThat(event.getOriginalHealAmount(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getOriginalFinalHealAmount(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getFinalHealAmount(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getBaseHealAmount(), is(closeTo(originalDamage, ERROR)));
}
use of org.spongepowered.api.event.entity.HealEntityEvent in project SpongeAPI by SpongePowered.
the class SpongeAbstractHealEntityEventTest method testSetBaseHealAmount.
@Test
public void testSetBaseHealAmount() {
Entity targetEntity = mockParam(Entity.class);
int originalDamage = 5;
HealEntityEvent event = SpongeEventFactory.createHealEntityEvent(Cause.of(EventContext.empty(), "none"), Lists.newArrayList(), targetEntity, originalDamage);
assertThat(event.getOriginalHealAmount(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getOriginalFinalHealAmount(), is(closeTo(originalDamage, ERROR)));
event.setBaseHealAmount(20);
assertThat(event.getBaseHealAmount(), is(closeTo(20, ERROR)));
assertThat(event.getFinalHealAmount(), is(closeTo(20, ERROR)));
assertThat(event.getOriginalHealAmount(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getOriginalFinalHealAmount(), is(closeTo(originalDamage, ERROR)));
}
use of org.spongepowered.api.event.entity.HealEntityEvent in project SpongeAPI by SpongePowered.
the class SpongeAbstractHealEntityEventTest method testUseModifiers.
@Test
public void testUseModifiers() {
Entity targetEntity = mockParam(Entity.class);
final int originalDamage = 1;
final int originalFinalDamage = 18;
final int firstModifierDamage = 2;
final int secondModifierDamage = 15;
HealthModifier firstModifer = mockParam(HealthModifier.class);
HealthModifier secondModifier = mockParam(HealthModifier.class);
List<HealthFunction> originalFunctions = Lists.newArrayList(HealthFunction.of(firstModifer, p -> p * 2), HealthFunction.of(secondModifier, p -> p * 5));
HealEntityEvent event = SpongeEventFactory.createHealEntityEvent(Cause.of(EventContext.empty(), "none"), originalFunctions, targetEntity, originalDamage);
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
assertThat(event.getOriginalHealAmount(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getOriginalFinalHealAmount(), is(closeTo(originalFinalDamage, ERROR)));
Map<HealthModifier, Double> originalDamages = event.getOriginalHealingAmounts();
assertThat(originalDamages.size(), is(originalFunctions.size()));
assertThat(originalDamages.get(firstModifer), is(closeTo(firstModifierDamage, ERROR)));
assertThat(originalDamages.get(secondModifier), is(closeTo(secondModifierDamage, ERROR)));
assertThat(event.getOriginalHealingModifierAmount(firstModifer), is(closeTo(firstModifierDamage, ERROR)));
assertThat(event.getOriginalHealingModifierAmount(secondModifier), is(closeTo(secondModifierDamage, ERROR)));
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
}
use of org.spongepowered.api.event.entity.HealEntityEvent in project SpongeAPI by SpongePowered.
the class SpongeAbstractHealEntityEventTest method testAddModifier.
@Test
public void testAddModifier() {
Entity targetEntity = mockParam(Entity.class);
final int originalDamage = 1;
final int originalFinalDamage = 18;
final int firstModifierDamage = 2;
final int secondModifierDamage = 15;
final int modifiedFinalDamage = 36;
final int thirdDamage = 18;
HealthModifier firstModifer = mockParam(HealthModifier.class);
HealthModifier secondModifier = mockParam(HealthModifier.class);
HealthModifier thirdModifier = mockParam(HealthModifier.class);
DoubleUnaryOperator thirdFunction = p -> p;
List<HealthFunction> originalFunctions = Lists.newArrayList(HealthFunction.of(firstModifer, p -> p * 2), HealthFunction.of(secondModifier, p -> p * 5));
List<HealthFunction> newFunctions = Lists.newArrayList(originalFunctions);
newFunctions.add(HealthFunction.of(thirdModifier, thirdFunction));
HealEntityEvent event = SpongeEventFactory.createHealEntityEvent(Cause.of(EventContext.empty(), "none"), originalFunctions, targetEntity, originalDamage);
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
assertThat(event.isModifierApplicable(thirdModifier), is(false));
event.setHealAmount(thirdModifier, thirdFunction);
assertThat(event.getHealAmount(firstModifer), is(closeTo(firstModifierDamage, ERROR)));
assertThat(event.getHealAmount(secondModifier), is(closeTo(secondModifierDamage, ERROR)));
assertThat(event.getHealAmount(thirdModifier), is(closeTo(thirdDamage, ERROR)));
assertThat(event.getOriginalHealingModifierAmount(firstModifer), is(closeTo(firstModifierDamage, ERROR)));
assertThat(event.getOriginalHealingModifierAmount(secondModifier), is(closeTo(secondModifierDamage, ERROR)));
assertThat(event.getOriginalHealAmount(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getOriginalFinalHealAmount(), is(closeTo(originalFinalDamage, ERROR)));
assertThat(event.getFinalHealAmount(), is(closeTo(modifiedFinalDamage, ERROR)));
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
assertThat(event.getModifiers(), is(Matchers.equalTo(newFunctions)));
}
Aggregations