mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-11-25 20:25:37 +01:00
Prevents damage to players with Essnetials God Mode on
https://github.com/BentoBoxWorld/AcidIsland/issues/93
This commit is contained in:
parent
e9656dedce
commit
9193bb9cbd
@ -5,6 +5,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -29,6 +30,8 @@ import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
|
||||
import world.bentobox.acidisland.AcidIsland;
|
||||
import world.bentobox.acidisland.events.AcidEvent;
|
||||
import world.bentobox.acidisland.events.AcidRainEvent;
|
||||
@ -45,6 +48,8 @@ public class AcidEffect implements Listener {
|
||||
private final AcidIsland addon;
|
||||
private final Map<Player, Long> burningPlayers = new HashMap<>();
|
||||
private final Map<Player, Long> wetPlayers = new HashMap<>();
|
||||
private Essentials essentials;
|
||||
private boolean essentialsCheck;
|
||||
private static final List<PotionEffectType> EFFECTS = Arrays.asList(
|
||||
PotionEffectType.BLINDNESS,
|
||||
PotionEffectType.CONFUSION,
|
||||
@ -176,7 +181,8 @@ public class AcidEffect implements Listener {
|
||||
* @return true if they are safe
|
||||
*/
|
||||
private boolean isSafeFromRain(Player player) {
|
||||
if (player.getWorld().getEnvironment().equals(Environment.NETHER)
|
||||
if (isEssentialsGodMode(player)
|
||||
|| 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
|
||||
@ -200,6 +206,8 @@ public class AcidEffect implements Listener {
|
||||
* @return true if player is safe
|
||||
*/
|
||||
private boolean isSafeFromAcid(Player player) {
|
||||
// Check for GodMode
|
||||
if (isEssentialsGodMode(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)
|
||||
@ -221,6 +229,19 @@ public class AcidEffect implements Listener {
|
||||
return player.getActivePotionEffects().stream().map(PotionEffect::getType).anyMatch(IMMUNE_EFFECTS::contains);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has Essentials God Mode enabled.
|
||||
* @param player - player
|
||||
* @return true if God Mode enabled, false if not or if Essentials plug does not exist
|
||||
*/
|
||||
private boolean isEssentialsGodMode(Player player) {
|
||||
if (!essentialsCheck && essentials == null) {
|
||||
essentials = (Essentials)Bukkit.getPluginManager().getPlugin("Essentials");
|
||||
essentialsCheck = true;
|
||||
}
|
||||
return essentials != null && essentials.getUser(player).isGodModeEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks what protection armor provides and slightly damages it as a result of the acid
|
||||
* @param le - player
|
||||
|
@ -34,6 +34,7 @@ import org.bukkit.inventory.ItemFactory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -44,10 +45,14 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.earth2me.essentials.Essentials;
|
||||
import com.earth2me.essentials.User;
|
||||
|
||||
import world.bentobox.acidisland.AISettings;
|
||||
import world.bentobox.acidisland.AcidIsland;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
@ -91,6 +96,12 @@ public class AcidEffectTest {
|
||||
private PlayerInventory inv;
|
||||
@Mock
|
||||
private ItemMeta itemMeta;
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
@Mock
|
||||
private Essentials essentials;
|
||||
@Mock
|
||||
private User essentialsUser;
|
||||
|
||||
|
||||
/**
|
||||
@ -98,11 +109,16 @@ public class AcidEffectTest {
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
|
||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
when(addon.getOverWorld()).thenReturn(world);
|
||||
|
||||
// Essentials
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
when(pim.getPlugin(eq("Essentials"))).thenReturn(essentials);
|
||||
when(essentials.getUser(any(Player.class))).thenReturn(essentialsUser);
|
||||
|
||||
// Player
|
||||
when(player.getGameMode()).thenReturn(GameMode.SURVIVAL);
|
||||
when(player.getWorld()).thenReturn(world);
|
||||
@ -235,6 +251,17 @@ 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 testOnPlayerMoveGodModeNoAcidAndRainDamage() {
|
||||
when(essentialsUser.isGodModeEnabled()).thenReturn(true);
|
||||
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)}.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user