mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-03 05:51:43 +01:00
parent
5573e9f329
commit
94b982f644
@ -48,11 +48,8 @@ public class FireListener extends FlagListener {
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBlockBurnEvent(BlockBurnEvent e) {
|
||||
onBlockBurn(e);
|
||||
}
|
||||
boolean onBlockBurn(BlockBurnEvent e) {
|
||||
return checkFire(e, e.getBlock().getLocation(), Flags.FIRE_BURNING);
|
||||
public void onBlockBurn(BlockBurnEvent e) {
|
||||
checkFire(e, e.getBlock().getLocation(), Flags.FIRE_BURNING);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,11 +57,10 @@ public class FireListener extends FlagListener {
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBlockSpreadEvent(BlockSpreadEvent e) {
|
||||
onBlockSpread(e);
|
||||
public void onBlockSpread(BlockSpreadEvent e) {
|
||||
if (e.getSource().getType().equals(Material.FIRE)) {
|
||||
checkFire(e, e.getBlock().getLocation(), Flags.FIRE_SPREAD);
|
||||
}
|
||||
boolean onBlockSpread(BlockSpreadEvent e) {
|
||||
return e.getSource().getType().equals(Material.FIRE)&& checkFire(e, e.getBlock().getLocation(), Flags.FIRE_SPREAD);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,12 +68,11 @@ public class FireListener extends FlagListener {
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBlockIgniteEvent(BlockIgniteEvent e) {
|
||||
onBlockIgnite(e);
|
||||
}
|
||||
boolean onBlockIgnite(BlockIgniteEvent e) {
|
||||
public void onBlockIgnite(BlockIgniteEvent e) {
|
||||
// Check if this is a portal lighting - that is allowed any time
|
||||
return !e.getBlock().getType().equals(Material.OBSIDIAN) && checkFire(e, e.getBlock().getLocation(), Flags.FIRE_IGNITE);
|
||||
if (!e.getBlock().getType().equals(Material.OBSIDIAN)) {
|
||||
checkFire(e, e.getBlock().getLocation(), Flags.FIRE_IGNITE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +99,7 @@ public class FireListener extends FlagListener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onLightningStrikeEvent(LightningStrikeEvent e) {
|
||||
checkFire(e, e.getLightning().getLocation(), Flags.FIRE_IGNITE);
|
||||
}
|
||||
|
@ -43,13 +43,10 @@ public class TNTListener extends FlagListener {
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onTNTDamageEvent(EntityChangeBlockEvent e) {
|
||||
onTNTDamage(e);
|
||||
}
|
||||
boolean onTNTDamage(EntityChangeBlockEvent e) {
|
||||
public void onTNTDamage(EntityChangeBlockEvent e) {
|
||||
// Check world
|
||||
if (!e.getBlock().getType().equals(Material.TNT) || !getIWM().inWorld(e.getBlock().getLocation())) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// Stop TNT from being damaged if it is being caused by a visitor with a flaming arrow
|
||||
if (e.getEntity() instanceof Projectile projectile) {
|
||||
@ -59,10 +56,8 @@ public class TNTListener extends FlagListener {
|
||||
// Remove the arrow
|
||||
projectile.remove();
|
||||
e.setCancelled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,6 +21,15 @@ import world.bentobox.bentobox.util.Util;
|
||||
*/
|
||||
public class MobSpawnListener extends FlagListener {
|
||||
|
||||
/**
|
||||
* Prevents mobs spawning naturally
|
||||
*
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onMobSpawnEvent(CreatureSpawnEvent e) {
|
||||
onMobSpawn(e);
|
||||
}
|
||||
/**
|
||||
* Prevents mobs spawning naturally
|
||||
*
|
||||
@ -28,10 +37,10 @@ public class MobSpawnListener extends FlagListener {
|
||||
* @return true if cancelled
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onMobSpawn(CreatureSpawnEvent e) {
|
||||
boolean onMobSpawn(CreatureSpawnEvent e) {
|
||||
// If not in the right world, or spawning is not natural return
|
||||
if (!getIWM().inWorld(e.getEntity().getLocation())) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
switch (e.getSpawnReason()) {
|
||||
// Natural
|
||||
@ -53,14 +62,14 @@ public class MobSpawnListener extends FlagListener {
|
||||
case VILLAGE_INVASION:
|
||||
boolean cancelNatural = shouldCancel(e.getEntity(), e.getLocation(), Flags.ANIMAL_NATURAL_SPAWN, Flags.MONSTER_NATURAL_SPAWN);
|
||||
e.setCancelled(cancelNatural);
|
||||
return;
|
||||
return cancelNatural;
|
||||
// Spawners
|
||||
case SPAWNER:
|
||||
boolean cancelSpawners = shouldCancel(e.getEntity(), e.getLocation(), Flags.ANIMAL_SPAWNERS_SPAWN, Flags.MONSTER_SPAWNERS_SPAWN);
|
||||
e.setCancelled(cancelSpawners);
|
||||
return;
|
||||
return cancelSpawners;
|
||||
default:
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,10 +33,18 @@ public class ObsidianScoopingListener extends FlagListener {
|
||||
* Enables changing of obsidian back into lava
|
||||
*
|
||||
* @param e event
|
||||
* @return false if obsidian not scooped, true if scooped
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerInteract(final PlayerInteractEvent e) {
|
||||
public void onPlayerInteractEvent(final PlayerInteractEvent e) {
|
||||
onPlayerInteract(e);
|
||||
}
|
||||
/**
|
||||
* Enables changing of obsidian back into lava
|
||||
*
|
||||
* @param e event
|
||||
* @return false if obsidian not scooped, true if scooped
|
||||
*/
|
||||
boolean onPlayerInteract(final PlayerInteractEvent e) {
|
||||
if (!getIWM().inWorld(e.getPlayer().getLocation())
|
||||
|| !Flags.OBSIDIAN_SCOOPING.isSetForWorld(e.getPlayer().getWorld())
|
||||
|| !e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)
|
||||
@ -44,9 +52,9 @@ public class ObsidianScoopingListener extends FlagListener {
|
||||
|| !(e.getItem() != null && e.getItem().getType().equals(Material.BUCKET))
|
||||
|| !(e.getClickedBlock() != null && e.getClickedBlock().getType().equals(Material.OBSIDIAN))
|
||||
|| e.getClickedBlock().getRelative(e.getBlockFace()).getType().equals(Material.WATER)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
lookForLava(e);
|
||||
return lookForLava(e);
|
||||
}
|
||||
|
||||
private boolean lookForLava(PlayerInteractEvent e) {
|
||||
|
@ -128,12 +128,12 @@ public class FireListenerTest {
|
||||
|
||||
// Player name
|
||||
PlayersManager pm = mock(PlayersManager.class);
|
||||
when(pm.getName(Mockito.any())).thenReturn("tastybento");
|
||||
when(pm.getName(any())).thenReturn("tastybento");
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// World Settings
|
||||
WorldSettings ws = mock(WorldSettings.class);
|
||||
when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
|
||||
when(iwm.getWorldSettings(any())).thenReturn(ws);
|
||||
|
||||
when(ws.getWorldFlags()).thenReturn(worldFlags);
|
||||
GameModeAddon gma = mock(GameModeAddon.class);
|
||||
@ -141,7 +141,7 @@ public class FireListenerTest {
|
||||
when(iwm.getAddon(any())).thenReturn(opGma);
|
||||
|
||||
PowerMockito.mockStatic(Util.class);
|
||||
when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
|
||||
when(Util.getWorld(any())).thenReturn(mock(World.class));
|
||||
}
|
||||
|
||||
@After
|
||||
@ -168,16 +168,16 @@ public class FireListenerTest {
|
||||
listener.setPlugin(plugin);
|
||||
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(any())).thenReturn(false);
|
||||
when(island.isAllowed(any(), any())).thenReturn(false);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(false);
|
||||
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(true);
|
||||
assertTrue(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
|
||||
// Allow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(any())).thenReturn(true);
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(false);
|
||||
assertFalse(listener.checkFire(e, location, Flags.FLINT_AND_STEEL));
|
||||
Flags.FLINT_AND_STEEL.setDefaultSetting(true);
|
||||
@ -211,20 +211,24 @@ public class FireListenerTest {
|
||||
listener.setPlugin(plugin);
|
||||
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(any())).thenReturn(false);
|
||||
when(island.isAllowed(any(), any())).thenReturn(false);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(false);
|
||||
assertTrue(listener.onBlockBurn(e));
|
||||
listener.onBlockBurn(e);
|
||||
assertTrue(e.isCancelled());
|
||||
Flags.FIRE_BURNING.setDefaultSetting(true);
|
||||
assertTrue(listener.onBlockBurn(e));
|
||||
listener.onBlockBurn(e);
|
||||
assertTrue(e.isCancelled());
|
||||
|
||||
// Allow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(any())).thenReturn(true);
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
Flags.FIRE_BURNING.setDefaultSetting(false);
|
||||
assertFalse(listener.onBlockBurn(e));
|
||||
listener.onBlockBurn(e);
|
||||
assertFalse(e.isCancelled());
|
||||
Flags.FIRE_BURNING.setDefaultSetting(true);
|
||||
assertFalse(listener.onBlockBurn(e));
|
||||
listener.onBlockBurn(e);
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
// Check with no island
|
||||
e = new BlockBurnEvent(block, block);
|
||||
@ -235,7 +239,8 @@ public class FireListenerTest {
|
||||
assertTrue(e.isCancelled());
|
||||
// Fire allowed
|
||||
Flags.FIRE_BURNING.setDefaultSetting(true);
|
||||
assertFalse(listener.onBlockBurn(e));
|
||||
listener.onBlockBurn(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -261,29 +266,35 @@ public class FireListenerTest {
|
||||
listener.setPlugin(plugin);
|
||||
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(any())).thenReturn(false);
|
||||
when(island.isAllowed(any(), any())).thenReturn(false);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(false);
|
||||
assertTrue(listener.onBlockSpread(e));
|
||||
listener.onBlockSpread(e);
|
||||
assertTrue(e.isCancelled());
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(true);
|
||||
assertTrue(listener.onBlockSpread(e));
|
||||
listener.onBlockSpread(e);
|
||||
assertTrue(e.isCancelled());
|
||||
|
||||
// Allow fire spread
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(any())).thenReturn(true);
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(false);
|
||||
assertFalse(listener.onBlockSpread(e));
|
||||
listener.onBlockSpread(e);
|
||||
assertFalse(e.isCancelled());
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(true);
|
||||
assertFalse(listener.onBlockSpread(e));
|
||||
listener.onBlockSpread(e);
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
// Check with no island
|
||||
when(im.getIslandAt(any())).thenReturn(Optional.empty());
|
||||
// Fire spread is not allowed, so should be cancelled
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(false);
|
||||
assertTrue(listener.onBlockSpread(e));
|
||||
listener.onBlockSpread(e);
|
||||
assertTrue(e.isCancelled());
|
||||
// Fire allowed
|
||||
Flags.FIRE_SPREAD.setDefaultSetting(true);
|
||||
assertFalse(listener.onBlockSpread(e));
|
||||
listener.onBlockSpread(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -307,34 +318,41 @@ public class FireListenerTest {
|
||||
listener.setPlugin(plugin);
|
||||
|
||||
// Obsidian is okay to ignite
|
||||
assertFalse(listener.onBlockIgnite(e));
|
||||
listener.onBlockIgnite(e);
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
// Now set to something flammable
|
||||
when(block.getType()).thenReturn(Material.OAK_PLANKS);
|
||||
|
||||
// Disallow fire
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(island.isAllowed(any())).thenReturn(false);
|
||||
when(island.isAllowed(any(), any())).thenReturn(false);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(false);
|
||||
assertTrue(listener.onBlockIgnite(e));
|
||||
listener.onBlockIgnite(e);
|
||||
assertTrue(e.isCancelled());
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(true);
|
||||
assertTrue(listener.onBlockIgnite(e));
|
||||
listener.onBlockIgnite(e);
|
||||
assertTrue(e.isCancelled());
|
||||
|
||||
// Allow fire spread
|
||||
when(island.isAllowed(Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(island.isAllowed(any())).thenReturn(true);
|
||||
when(island.isAllowed(any(), any())).thenReturn(true);
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(false);
|
||||
assertFalse(listener.onBlockIgnite(e));
|
||||
listener.onBlockIgnite(e);
|
||||
assertFalse(e.isCancelled());
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(true);
|
||||
assertFalse(listener.onBlockIgnite(e));
|
||||
listener.onBlockIgnite(e);
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
// Check with no island
|
||||
when(im.getIslandAt(any())).thenReturn(Optional.empty());
|
||||
// Fire spread is not allowed, so should be cancelled
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(false);
|
||||
assertTrue(listener.onBlockIgnite(e));
|
||||
listener.onBlockIgnite(e);
|
||||
assertTrue(e.isCancelled());
|
||||
// Fire allowed
|
||||
Flags.FIRE_IGNITE.setDefaultSetting(true);
|
||||
assertFalse(listener.onBlockIgnite(e));
|
||||
listener.onBlockIgnite(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
when(block.getType()).thenReturn(Material.TNT);
|
||||
// Entity is not a projectile
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(player, block, Material.AIR.createBlockData());
|
||||
assertFalse(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertFalse(e.isCancelled());
|
||||
|
||||
}
|
||||
@ -163,7 +163,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
// Out of world
|
||||
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(player, block, Material.AIR.createBlockData());
|
||||
assertFalse(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
@Test
|
||||
@ -173,7 +173,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
// Out of world
|
||||
when(iwm.inWorld(any(Location.class))).thenReturn(false);
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(player, block, Material.AIR.createBlockData());
|
||||
assertFalse(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertFalse(e.isCancelled());
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
when(arrow.getFireTicks()).thenReturn(10);
|
||||
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(arrow, block, Material.AIR.createBlockData());
|
||||
assertFalse(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertFalse(e.isCancelled());
|
||||
verify(arrow, never()).remove();
|
||||
}
|
||||
@ -209,7 +209,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
when(arrow.getFireTicks()).thenReturn(0);
|
||||
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(arrow, block, Material.AIR.createBlockData());
|
||||
assertFalse(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertFalse(e.isCancelled());
|
||||
verify(arrow, never()).remove();
|
||||
|
||||
@ -228,7 +228,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
when(arrow.getFireTicks()).thenReturn(10);
|
||||
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(arrow, block, Material.AIR.createBlockData());
|
||||
assertTrue(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertTrue(e.isCancelled());
|
||||
verify(arrow).remove();
|
||||
|
||||
@ -249,7 +249,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
when(island.isAllowed(any(), eq(Flags.TNT_PRIMING))).thenReturn(true);
|
||||
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(arrow, block, Material.AIR.createBlockData());
|
||||
assertFalse(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertFalse(e.isCancelled());
|
||||
verify(arrow, never()).remove();
|
||||
|
||||
@ -270,7 +270,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
when(arrow.getFireTicks()).thenReturn(10);
|
||||
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(arrow, block, Material.AIR.createBlockData());
|
||||
assertTrue(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertTrue(e.isCancelled());
|
||||
verify(arrow).remove();
|
||||
|
||||
@ -291,7 +291,7 @@ public class TNTListenerTest extends AbstractCommonSetup {
|
||||
when(arrow.getFireTicks()).thenReturn(10);
|
||||
|
||||
EntityChangeBlockEvent e = new EntityChangeBlockEvent(arrow, block, Material.AIR.createBlockData());
|
||||
assertFalse(listener.onTNTDamage(e));
|
||||
listener.onTNTDamage(e);
|
||||
assertFalse(e.isCancelled());
|
||||
verify(arrow, never()).remove();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user