From 2c99121312f8b8642c57b7c3ed772e7fb40b8d19 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 11 Dec 2019 16:18:06 -0800 Subject: [PATCH] Fixed acid rain detection to skip nether or end environments. Also fixed more fundamental bug around acid rain detection. https://github.com/BentoBoxWorld/AcidIsland/issues/76 --- .../acidisland/listeners/AcidEffect.java | 9 +++-- .../acidisland/listeners/AcidEffectTest.java | 34 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java index 308a60d..21228ba 100644 --- a/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java +++ b/src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java @@ -9,6 +9,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.World.Environment; import org.bukkit.attribute.Attribute; import org.bukkit.block.BlockFace; import org.bukkit.entity.EntityType; @@ -177,11 +178,13 @@ public class AcidEffect implements Listener { * @return true if they are safe */ private boolean isSafeFromRain(Player player) { - if (addon.getSettings().isHelmetProtection() && (player.getInventory().getHelmet() != null - && player.getInventory().getHelmet().getType().name().contains("HELMET")) + if (player.getWorld().getEnvironment().equals(Environment.NETHER) + || player.getWorld().getEnvironment().equals(Environment.THE_END) + || (addon.getSettings().isHelmetProtection() && (player.getInventory().getHelmet() != null && player.getInventory().getHelmet().getType().name().contains("HELMET"))) || (!addon.getSettings().isAcidDamageSnow() && player.getLocation().getBlock().getTemperature() < 0.1) // snow falls || player.getLocation().getBlock().getHumidity() == 0 // dry - || (player.getActivePotionEffects().stream().map(PotionEffect::getType).anyMatch(IMMUNE_EFFECTS::contains))) { + || (player.getActivePotionEffects().stream().map(PotionEffect::getType).anyMatch(IMMUNE_EFFECTS::contains)) + ) { return true; } // Check if all air above player diff --git a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java index 43bc5a3..ab7e93c 100644 --- a/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java +++ b/src/test/java/world/bentobox/acidisland/listeners/AcidEffectTest.java @@ -18,6 +18,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.World.Environment; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.block.Block; @@ -146,6 +147,7 @@ public class AcidEffectTest { when(world.hasStorm()).thenReturn(true); when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(airBlock); when(world.getMaxHeight()).thenReturn(5); + when(world.getEnvironment()).thenReturn(Environment.NORMAL); ae = new AcidEffect(addon); } @@ -305,6 +307,38 @@ public class AcidEffectTest { verify(settings).getAcidDamageDelay(); } + /** + * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. + */ + @Test + public void testOnPlayerMoveAcidRainWrongWorld() { + World nether = mock(World.class); + when(nether.getName()).thenReturn("world_nether"); + when(nether.getEnvironment()).thenReturn(Environment.NETHER); + when(player.getWorld()).thenReturn(nether); + + PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); + ae.onPlayerMove(e); + // 2 times only + verify(addon, times(2)).getPlugin(); + } + + /** + * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. + */ + @Test + public void testOnPlayerMoveAcidRainWrongWorldEnd() { + World end = mock(World.class); + when(end.getName()).thenReturn("world_end"); + when(end.getEnvironment()).thenReturn(Environment.THE_END); + when(player.getWorld()).thenReturn(end); + + PlayerMoveEvent e = new PlayerMoveEvent(player, from, to); + ae.onPlayerMove(e); + // 2 times only + verify(addon, times(2)).getPlugin(); + } + /** * Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}. */