Add new DamageSource parameter 'null' to test events

This commit is contained in:
tastybento 2024-02-12 19:56:10 -08:00
parent 01f51f4d29
commit 87054687f0
7 changed files with 98 additions and 66 deletions

View File

@ -72,7 +72,7 @@ public class RanksManager {
if (!handler.objectExists(Ranks.ID)) {
// Make the initial object
DEFAULT_RANKS.forEach((ref, rank) -> ranksPut(ref, rank));
handler.saveObject(new Ranks(ranks));
save();
} else {
// Load the ranks from the database
Objects.requireNonNull(handler.loadObject(Ranks.ID)).getRankReference()
@ -81,6 +81,10 @@ public class RanksManager {
}
private void save() {
handler.saveObject(new Ranks(ranks));
}
/**
* Check if a rank exists
* @param reference YAML reference to rank, e.g., ranks.trusted
@ -101,7 +105,6 @@ public class RanksManager {
return false;
}
ranksPut(reference, value);
return true;
}
@ -110,6 +113,7 @@ public class RanksManager {
// Sort
ranks = ranks.entrySet().stream().sorted(Map.Entry.comparingByValue())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
save();
}
/**
@ -118,8 +122,11 @@ public class RanksManager {
* @return true if removed
*/
public boolean removeRank(String reference) {
return ranks.remove(reference) != null;
boolean result = ranks.remove(reference) != null;
if (result) {
save();
}
return result;
}
/**

View File

@ -384,7 +384,7 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
DamageCause cause = DamageCause.ENTITY_ATTACK;
Entity damagee = player;
Entity damager = player;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
}
@ -397,15 +397,15 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
DamageCause cause = DamageCause.ENTITY_ATTACK;
Entity damagee = mock(ArmorStand.class);
Entity damager = player;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
damagee = mock(ItemFrame.class);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
damagee = mock(EnderCrystal.class);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
}
@ -420,17 +420,17 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Entity damagee = mock(ArmorStand.class);
when(damagee.getLocation()).thenReturn(location);
Entity damager = player;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
damagee = mock(ItemFrame.class);
when(damagee.getLocation()).thenReturn(location);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
damagee = mock(EnderCrystal.class);
when(damagee.getLocation()).thenReturn(location);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
verify(notifier, times(3)).notify(any(), eq("protection.protected"));
@ -445,15 +445,15 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Entity damagee = mock(ArmorStand.class);
Projectile damager = mock(Projectile.class);
when(damager.getShooter()).thenReturn(player);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
damagee = mock(ItemFrame.class);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
damagee = mock(EnderCrystal.class);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
}
@ -467,15 +467,15 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
Entity damagee = mock(ArmorStand.class);
Projectile damager = mock(Projectile.class);
when(damager.getShooter()).thenReturn(mock(Skeleton.class));
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
damagee = mock(ItemFrame.class);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
damagee = mock(EnderCrystal.class);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertFalse(e.isCancelled());
}
@ -491,21 +491,21 @@ public class BreakBlocksListenerTest extends AbstractCommonSetup {
when(damagee.getLocation()).thenReturn(location);
Projectile damager = mock(Projectile.class);
when(damager.getShooter()).thenReturn(player);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
verify(damagee).setFireTicks(0);
damagee = mock(ItemFrame.class);
when(damagee.getLocation()).thenReturn(location);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
verify(damagee).setFireTicks(0);
damagee = mock(EnderCrystal.class);
when(damagee.getLocation()).thenReturn(location);
e = new EntityDamageByEntityEvent(damager, damagee, cause, 10);
e = new EntityDamageByEntityEvent(damager, damagee, cause, null, 10);
bbl.onEntityDamage(e);
assertTrue(e.isCancelled());
verify(notifier, times(3)).notify(any(), eq("protection.protected"));

View File

@ -77,7 +77,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnEntityDamageMonsteronMonster() {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, enderman, null, 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, enderman, null, null, 0);
HurtingListener hl = new HurtingListener();
hl.onEntityDamage(e);
assertFalse(e.isCancelled());
@ -88,7 +88,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
*/
@Test
public void testOnEntityDamagePlayeronMonster() {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, enderman, null, 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, enderman, null, null, 0);
HurtingListener hl = new HurtingListener();
hl.onEntityDamage(e);
assertTrue(e.isCancelled());
@ -101,7 +101,7 @@ public class HurtingListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityDamagePlayeronMonsterOp() {
when(player.isOp()).thenReturn(true);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, enderman, null, 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, enderman, null, null, 0);
HurtingListener hl = new HurtingListener();
hl.onEntityDamage(e);
assertFalse(e.isCancelled());

View File

@ -299,7 +299,8 @@ public class TNTListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityExplosion() {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, 20D);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertTrue(e.isCancelled());
}
@ -309,7 +310,8 @@ public class TNTListenerTest extends AbstractCommonSetup {
Flags.WORLD_TNT_DAMAGE.setDefaultSetting(false);
assertFalse(Flags.WORLD_TNT_DAMAGE.isSetForWorld(world));
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, 20D);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertTrue(e.isCancelled());
}
@ -319,7 +321,8 @@ public class TNTListenerTest extends AbstractCommonSetup {
Flags.WORLD_TNT_DAMAGE.setDefaultSetting(true);
assertTrue(Flags.WORLD_TNT_DAMAGE.isSetForWorld(world));
when(im.getProtectedIslandAt(any())).thenReturn(Optional.empty());
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, 20D);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertFalse(e.isCancelled());
}
@ -327,7 +330,8 @@ public class TNTListenerTest extends AbstractCommonSetup {
@Test
public void testOnEntityExplosionWrongWorld() {
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, 20D);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, player, DamageCause.ENTITY_EXPLOSION, null,
20D);
listener.onExplosion(e);
assertFalse(e.isCancelled());
}

View File

@ -252,7 +252,8 @@ public class PVPListenerTest {
public void testOnEntityDamageNotPlayer() {
Entity damager = mock(Zombie.class);
Entity damagee = mock(Creeper.class);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -265,7 +266,8 @@ public class PVPListenerTest {
@Test
public void testOnEntityDamageSelfDamage() {
Entity damager = mock(Player.class);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damager, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damager,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -281,7 +283,8 @@ public class PVPListenerTest {
when(player2.hasMetadata(eq("NPC"))).thenReturn(true);
// PVP is not allowed
when(island.isAllowed(any())).thenReturn(false);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -304,21 +307,22 @@ public class PVPListenerTest {
when(damagee.getWorld()).thenReturn(world);
when(damager.getLocation()).thenReturn(loc);
when(damagee.getLocation()).thenReturn(loc);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled());
// Different attack type
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK,
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled());
// Wrong world
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
wrongWorld();
@ -346,13 +350,14 @@ public class PVPListenerTest {
when(iwm.getIvSettings(world)).thenReturn(visitorProtectionList);
// This player is on their island, i.e., not a visitor
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled());
// Wrong world
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
wrongWorld();
@ -376,7 +381,8 @@ public class PVPListenerTest {
// This player is a visitor
when(im.userIsOnIsland(any(), any())).thenReturn(false);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -403,7 +409,8 @@ public class PVPListenerTest {
// This player is a visitor
when(im.userIsOnIsland(any(), any())).thenReturn(false);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
wrongWorld();
@ -431,7 +438,8 @@ public class PVPListenerTest {
// This player is a visitor
when(im.userIsOnIsland(any(), any())).thenReturn(false);
// Damage is not entity attack
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.THORNS,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee,
EntityDamageEvent.DamageCause.THORNS, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -458,13 +466,14 @@ public class PVPListenerTest {
// This player is a visitor
when(im.userIsOnIsland(any(), any())).thenReturn(false);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(damager, damagee,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
assertFalse(e.isCancelled());
// Wrong world
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
e = new EntityDamageByEntityEvent(damager, damagee, EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
wrongWorld();
@ -489,7 +498,8 @@ public class PVPListenerTest {
@Test
public void testOnEntityDamagePVPNotAllowed() {
// No visitor protection
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -504,7 +514,8 @@ public class PVPListenerTest {
*/
@Test
public void testOnEntityDamagePVPNotAllowedInvVisitor() {
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
@ -525,7 +536,8 @@ public class PVPListenerTest {
public void testOnEntityDamageOnPVPAllowed() {
// PVP is allowed
when(island.isAllowed(any())).thenReturn(true);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(player, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -552,7 +564,8 @@ public class PVPListenerTest {
when(p.getShooter()).thenReturn(player);
when(p.getLocation()).thenReturn(loc);
when(p.getWorld()).thenReturn(world);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -580,7 +593,8 @@ public class PVPListenerTest {
Projectile p = mock(Projectile.class);
when(p.getShooter()).thenReturn(player);
when(p.getLocation()).thenReturn(loc);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -598,7 +612,8 @@ public class PVPListenerTest {
when(p.getLocation()).thenReturn(loc);
// PVP is allowed
when(island.isAllowed(any())).thenReturn(true);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -626,7 +641,8 @@ public class PVPListenerTest {
when(p.getLocation()).thenReturn(loc);
// PVP is allowed
when(island.isAllowed(any())).thenReturn(true);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -646,7 +662,8 @@ public class PVPListenerTest {
when(p.getLocation()).thenReturn(loc);
// PVP is allowed
when(island.isAllowed(any())).thenReturn(true);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2, EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, player2,
EntityDamageEvent.DamageCause.ENTITY_ATTACK, null,
new EnumMap<>(ImmutableMap.of(DamageModifier.BASE, 0D)),
new EnumMap<DamageModifier, Function<? super Double, Double>>(ImmutableMap.of(DamageModifier.BASE, Functions.constant(-0.0))));
new PVPListener().onEntityDamage(e);
@ -1126,7 +1143,8 @@ public class PVPListenerTest {
listener.onPlayerShootFireworkEvent(e);
// Now damage
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_ATTACK, 0);
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_ATTACK, null,
0);
listener.onEntityDamage(en);
assertFalse(en.isCancelled());
}
@ -1142,7 +1160,7 @@ public class PVPListenerTest {
EntityShootBowEvent e = new EntityShootBowEvent(player, bow, null, arrow, EquipmentSlot.HAND, 1F, false);
listener.onPlayerShootFireworkEvent(e);
// Now damage
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(arrow, player, DamageCause.ENTITY_ATTACK, 0);
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(arrow, player, DamageCause.ENTITY_ATTACK, null, 0);
listener.onEntityDamage(en);
assertFalse(en.isCancelled());
}
@ -1163,7 +1181,8 @@ public class PVPListenerTest {
listener.onPlayerShootFireworkEvent(e);
// Now damage
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_EXPLOSION, 0);
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player, DamageCause.ENTITY_EXPLOSION,
null, 0);
listener.onEntityDamage(en);
assertFalse(en.isCancelled());
}
@ -1185,7 +1204,8 @@ public class PVPListenerTest {
listener.onPlayerShootFireworkEvent(e);
// Now damage
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player2, DamageCause.ENTITY_EXPLOSION, 0);
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player2, DamageCause.ENTITY_EXPLOSION,
null, 0);
listener.onEntityDamage(en);
assertTrue(en.isCancelled());
}
@ -1206,7 +1226,8 @@ public class PVPListenerTest {
listener.onPlayerShootFireworkEvent(e);
// Now damage
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player2, DamageCause.ENTITY_EXPLOSION, 0);
EntityDamageByEntityEvent en = new EntityDamageByEntityEvent(firework, player2, DamageCause.ENTITY_EXPLOSION,
null, 0);
listener.onEntityDamage(en);
assertFalse(en.isCancelled());
}

View File

@ -247,7 +247,7 @@ public class InvincibleVisitorsListenerTest {
@Test
public void testOnVisitorGetDamageNotPlayer() {
LivingEntity le = mock(LivingEntity.class);
EntityDamageEvent e = new EntityDamageEvent(le, EntityDamageEvent.DamageCause.CRAMMING, 0D);
EntityDamageEvent e = new EntityDamageEvent(le, EntityDamageEvent.DamageCause.CRAMMING, null, 0D);
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());
}
@ -256,7 +256,7 @@ public class InvincibleVisitorsListenerTest {
public void testOnVisitorGetDamageNotInWorld() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, null, 0D);
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());
}
@ -265,14 +265,14 @@ public class InvincibleVisitorsListenerTest {
public void testOnVisitorGetDamageNotInIvSettings() {
when(iwm.inWorld(any(World.class))).thenReturn(false);
when(iwm.inWorld(any(Location.class))).thenReturn(false);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, null, 0D);
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());
}
@Test
public void testOnVisitorGetDamageNotVisitor() {
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, null, 0D);
when(im.userIsOnIsland(any(), any())).thenReturn(true);
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());
@ -280,7 +280,7 @@ public class InvincibleVisitorsListenerTest {
@Test
public void testOnVisitorGetDamageNotVoid() {
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, null, 0D);
listener.onVisitorGetDamage(e);
assertTrue(e.isCancelled());
verify(player, never()).setGameMode(eq(GameMode.SPECTATOR));
@ -290,7 +290,7 @@ public class InvincibleVisitorsListenerTest {
@Test
public void testOnVisitorGetDamageNPC() {
when(player.hasMetadata(eq("NPC"))).thenReturn(true);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, null, 0D);
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());
}
@ -299,7 +299,7 @@ public class InvincibleVisitorsListenerTest {
@Test
public void testOnVisitorGetDamageVoidIslandHere() {
when(im.getIslandAt(any())).thenReturn(optionalIsland);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.VOID, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.VOID, null, 0D);
// Player should be teleported to this island
listener.onVisitorGetDamage(e);
assertTrue(e.isCancelled());
@ -310,7 +310,7 @@ public class InvincibleVisitorsListenerTest {
public void testOnVisitorGetDamageVoidNoIslandHerePlayerHasNoIsland() {
when(im.getIslandAt(any())).thenReturn(Optional.empty());
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.VOID, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.VOID, null, 0D);
// Player should die
listener.onVisitorGetDamage(e);
assertFalse(e.isCancelled());
@ -323,7 +323,7 @@ public class InvincibleVisitorsListenerTest {
when(im.getIslandAt(any())).thenReturn(Optional.empty());
// Player has an island
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.VOID, 0D);
EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.VOID, null, 0D);
// Player should be teleported to their island
listener.onVisitorGetDamage(e);
assertTrue(e.isCancelled());

View File

@ -155,7 +155,7 @@ public class ItemFrameListenerTest {
public void testOnItemFrameDamageEntityDamageByEntityEvent() {
ItemFrameListener ifl = new ItemFrameListener();
DamageCause cause = DamageCause.ENTITY_ATTACK;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, entity, cause , 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, entity, cause, null, 0);
ifl.onItemFrameDamage(e);
assertTrue(e.isCancelled());
}
@ -169,7 +169,7 @@ public class ItemFrameListenerTest {
Creeper creeper = mock(Creeper.class);
when(creeper.getLocation()).thenReturn(location);
DamageCause cause = DamageCause.ENTITY_ATTACK;
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, creeper, cause , 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, creeper, cause, null, 0);
ifl.onItemFrameDamage(e);
assertFalse(e.isCancelled());
}
@ -183,7 +183,7 @@ public class ItemFrameListenerTest {
DamageCause cause = DamageCause.ENTITY_ATTACK;
Projectile p = mock(Projectile.class);
when(p.getShooter()).thenReturn(enderman);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, entity, cause , 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, entity, cause, null, 0);
ifl.onItemFrameDamage(e);
assertTrue(e.isCancelled());
}
@ -198,7 +198,7 @@ public class ItemFrameListenerTest {
Projectile p = mock(Projectile.class);
Player player = mock(Player.class);
when(p.getShooter()).thenReturn(player);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, entity, cause , 0);
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, entity, cause, null, 0);
ifl.onItemFrameDamage(e);
assertFalse(e.isCancelled());
}