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
This commit is contained in:
tastybento 2019-12-11 16:18:06 -08:00
parent 4eb8a3327f
commit 2c99121312
2 changed files with 40 additions and 3 deletions

View File

@ -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

View File

@ -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)}.
*/