Protects visitors from acid damage.

Sets default for to allow acid damage for visitors.

Fixes https://github.com/BentoBoxWorld/AcidIsland/issues/93
This commit is contained in:
tastybento 2020-08-14 15:31:07 -07:00
parent cfbda44e1f
commit 6708937c17
4 changed files with 59 additions and 7 deletions

View File

@ -19,6 +19,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.EntityEquipment;
@ -36,6 +37,7 @@ import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.events.AcidEvent;
import world.bentobox.acidisland.events.AcidRainEvent;
import world.bentobox.acidisland.world.AcidTask;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
/**
@ -188,6 +190,9 @@ public class AcidEffect implements Listener {
|| (!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))
// Protect visitors
|| (addon.getPlugin().getIWM().getIvSettings(player.getWorld()).contains(DamageCause.CUSTOM.name())
&& !addon.getIslands().userIsOnIsland(player.getWorld(), User.getInstance(player)))
) {
return true;
}
@ -207,7 +212,13 @@ public class AcidEffect implements Listener {
*/
private boolean isSafeFromAcid(Player player) {
// Check for GodMode
if (isEssentialsGodMode(player)) return true;
if (isEssentialsGodMode(player)
// Protect visitors
|| (addon.getPlugin().getIWM().getIvSettings(player.getWorld()).contains(DamageCause.CUSTOM.name())
&& !addon.getIslands().userIsOnIsland(player.getWorld(), User.getInstance(player)))
) {
return true;
}
// Not in liquid or on snow
if (!player.getLocation().getBlock().getType().equals(Material.WATER)
&& !player.getLocation().getBlock().getType().equals(Material.BUBBLE_COLUMN)

View File

@ -22,7 +22,6 @@ import org.bukkit.scheduler.BukkitTask;
import world.bentobox.acidisland.AcidIsland;
import world.bentobox.acidisland.listeners.AcidEffect;
import world.bentobox.bentobox.BentoBox;
public class AcidTask {
private final AcidIsland addon;

View File

@ -443,7 +443,6 @@ protection:
invincible-visitors:
- BLOCK_EXPLOSION
- CONTACT
- CUSTOM
- DROWNING
- ENTITY_ATTACK
- ENTITY_EXPLOSION

View File

@ -12,6 +12,7 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -55,6 +56,9 @@ import com.earth2me.essentials.User;
import world.bentobox.acidisland.AISettings;
import world.bentobox.acidisland.AcidIsland;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.util.Util;
@ -102,6 +106,12 @@ public class AcidEffectTest {
private Essentials essentials;
@Mock
private User essentialsUser;
@Mock
private BentoBox plugin;
@Mock
private IslandWorldManager iwm;
@Mock
private IslandsManager im;
/**
@ -165,6 +175,16 @@ public class AcidEffectTest {
when(world.getMaxHeight()).thenReturn(5);
when(world.getEnvironment()).thenReturn(Environment.NORMAL);
// Plugin
when(addon.getPlugin()).thenReturn(plugin);
when(plugin.getIWM()).thenReturn(iwm);
// CUSTOM damage protection
when(iwm.getIvSettings(any())).thenReturn(Collections.singletonList("CUSTOM"));
// Island manager
when(addon.getIslands()).thenReturn(im);
when(im.userIsOnIsland(any(), any())).thenReturn(true);
ae = new AcidEffect(addon);
}
@ -251,6 +271,29 @@ public class AcidEffectTest {
verify(settings, times(2)).getAcidDamageDelay();
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/
@Test
public void testOnPlayerMoveVisitorNoAcidAndRainDamage() {
when(im.userIsOnIsland(any(), any())).thenReturn(false);
PlayerMoveEvent e = new PlayerMoveEvent(player, from, to);
ae.onPlayerMove(e);
verify(settings, never()).getAcidDamageDelay();
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/
@Test
public void testOnPlayerMoveVisitorAcidAndRainDamage() {
// No protection against CUSTOM damage
when(iwm.getIvSettings(any())).thenReturn(Collections.emptyList());
PlayerMoveEvent e = new PlayerMoveEvent(player, from, to);
ae.onPlayerMove(e);
verify(settings, times(2)).getAcidDamageDelay();
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)}.
*/
@ -346,8 +389,8 @@ public class AcidEffectTest {
PlayerMoveEvent e = new PlayerMoveEvent(player, from, to);
ae.onPlayerMove(e);
// 2 times only
verify(addon, times(2)).getPlugin();
// 3 times only
verify(addon, times(3)).getPlugin();
}
/**
@ -362,8 +405,8 @@ public class AcidEffectTest {
PlayerMoveEvent e = new PlayerMoveEvent(player, from, to);
ae.onPlayerMove(e);
// 2 times only
verify(addon, times(2)).getPlugin();
// 3 times only
verify(addon, times(3)).getPlugin();
}
/**