mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-11-22 10:36:07 +01:00
Added acidrain test method
This commit is contained in:
parent
1d3be20237
commit
39a7df44ee
@ -159,6 +159,11 @@ public class AcidEffect implements Listener {
|
||||
}.runTaskTimer(addon.getPlugin(), 0L, 20L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if it is still raining or player is safe or dead or there is no damage
|
||||
* @param player player
|
||||
* @return true if the acid raid damage should stop
|
||||
*/
|
||||
protected boolean checkForRain(Player player) {
|
||||
if (!addon.getOverWorld().hasStorm() || player.isDead() || isSafeFromRain(player) || addon.getSettings().getAcidRainDamage() <= 0D) {
|
||||
wetPlayers.remove(player);
|
||||
@ -168,7 +173,7 @@ public class AcidEffect implements Listener {
|
||||
double protection = addon.getSettings().getAcidRainDamage() * getDamageReduced(player);
|
||||
double totalDamage = Math.max(0, addon.getSettings().getAcidRainDamage() - protection);
|
||||
AcidRainEvent event = new AcidRainEvent(player, totalDamage, protection, addon.getSettings().getAcidRainEffects());
|
||||
addon.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
event.getPotionEffects().stream().filter(EFFECTS::contains).forEach(t -> player.addPotionEffect(new PotionEffect(t, addon.getSettings().getRainEffectDuation() * 20, 1)));
|
||||
// Apply damage if there is any
|
||||
|
@ -1,5 +1,6 @@
|
||||
package world.bentobox.acidisland.listeners;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
@ -18,6 +19,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
@ -112,6 +114,8 @@ public class AcidEffectTest {
|
||||
private IslandWorldManager iwm;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private Server server;
|
||||
|
||||
|
||||
/**
|
||||
@ -185,6 +189,7 @@ public class AcidEffectTest {
|
||||
when(addon.getIslands()).thenReturn(im);
|
||||
when(im.userIsOnIsland(any(), any())).thenReturn(true);
|
||||
|
||||
|
||||
ae = new AcidEffect(addon);
|
||||
}
|
||||
|
||||
@ -582,4 +587,63 @@ public class AcidEffectTest {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#checkForRain(Player)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckForRain() {
|
||||
when(world.hasStorm()).thenReturn(true);
|
||||
when(player.isDead()).thenReturn(false);
|
||||
when(settings.getAcidRainDamage()).thenReturn(10);
|
||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||
assertFalse(ae.checkForRain(player));
|
||||
when(world.hasStorm()).thenReturn(false);
|
||||
when(player.isDead()).thenReturn(false);
|
||||
when(settings.getAcidRainDamage()).thenReturn(10);
|
||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||
assertTrue(ae.checkForRain(player));
|
||||
when(world.hasStorm()).thenReturn(true);
|
||||
when(player.isDead()).thenReturn(true);
|
||||
when(settings.getAcidRainDamage()).thenReturn(10);
|
||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||
assertTrue(ae.checkForRain(player));
|
||||
when(world.hasStorm()).thenReturn(true);
|
||||
when(player.isDead()).thenReturn(false);
|
||||
when(settings.getAcidRainDamage()).thenReturn(0);
|
||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||
assertTrue(ae.checkForRain(player));
|
||||
when(world.hasStorm()).thenReturn(true);
|
||||
when(player.isDead()).thenReturn(false);
|
||||
when(settings.getAcidRainDamage()).thenReturn(10);
|
||||
when(world.getEnvironment()).thenReturn(Environment.NETHER);
|
||||
assertTrue(ae.checkForRain(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#checkForRain(Player)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCheckForRainWetPlayer() {
|
||||
AttributeInstance value = mock(AttributeInstance.class);
|
||||
when(value.getValue()).thenReturn(20D);
|
||||
// Diamond armor
|
||||
when(player.getAttribute(eq(Attribute.GENERIC_ARMOR))).thenReturn(value);
|
||||
EntityEquipment equip = mock(EntityEquipment.class);
|
||||
when(equip.getBoots()).thenReturn(new ItemStack(Material.DIAMOND_BOOTS));
|
||||
when(equip.getHelmet()).thenReturn(new ItemStack(Material.DIAMOND_HELMET));
|
||||
when(equip.getLeggings()).thenReturn(new ItemStack(Material.DIAMOND_LEGGINGS));
|
||||
when(equip.getChestplate()).thenReturn(new ItemStack(Material.DIAMOND_CHESTPLATE));
|
||||
when(player.getEquipment()).thenReturn(equip);
|
||||
|
||||
when(settings.getAcidDamageDelay()).thenReturn(0L);
|
||||
when(world.hasStorm()).thenReturn(true);
|
||||
when(player.isDead()).thenReturn(false);
|
||||
when(settings.getAcidRainDamage()).thenReturn(10);
|
||||
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
|
||||
testOnPlayerMoveAcidAndRainDamage();
|
||||
|
||||
assertFalse(ae.checkForRain(player));
|
||||
verify(player).damage(2.0d); // Reduced due to armor
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user