Prevent chest boats from causing acid damage.

Fixes #146. Added test classes too.
This commit is contained in:
tastybento 2024-01-08 20:33:32 +09:00
parent 40b382d878
commit 198cc66319
3 changed files with 56 additions and 8 deletions

View File

@ -258,7 +258,7 @@ public class AcidEffect implements Listener {
* @param player - player
* @return true if player is safe
*/
private boolean isSafeFromAcid(Player player) {
boolean isSafeFromAcid(Player player) {
// Check for GodMode
if (isEssentialsGodMode(player)
// Protect visitors
@ -275,7 +275,8 @@ public class AcidEffect implements Listener {
return true;
}
// Check if player is on a boat
if (player.getVehicle() != null && player.getVehicle().getType().equals(EntityType.BOAT)) {
if (player.getVehicle() != null && (player.getVehicle().getType().equals(EntityType.BOAT)
|| player.getVehicle().getType().equals(EntityType.CHEST_BOAT))) {
// I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT! SNL Sketch. https://youtu.be/avaSdC0QOUM.
return true;
}

View File

@ -60,7 +60,6 @@ import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.RanksManager;
/**
* @author tastybento
@ -202,11 +201,6 @@ public class AcidIslandTest {
// Settings
when(plugin.getSettings()).thenReturn(settings);
// RanksManager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);
}
/**

View File

@ -648,4 +648,57 @@ public class AcidEffectTest {
verify(player).damage(2.0d); // Reduced due to armor
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#isSafeFromAcid(Player)}.
*/
@Test
public void testIsSafeFromAcid() {
assertFalse(ae.isSafeFromAcid(player));
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#isSafeFromAcid(Player)}.
*/
@Test
public void testIsSafeFromAcidEssentialGodMode() {
when(essentialsUser.isGodModeEnabled()).thenReturn(true);
assertTrue(ae.isSafeFromAcid(player));
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#isSafeFromAcid(Player)}.
*/
@Test
public void testIsSafeFromAcidBoat() {
when(player.isInsideVehicle()).thenReturn(true);
Entity boat = mock(Entity.class);
when(boat.getType()).thenReturn(EntityType.BOAT);
when(player.getVehicle()).thenReturn(boat);
assertTrue(ae.isSafeFromAcid(player));
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#isSafeFromAcid(Player)}.
*/
@Test
public void testIsSafeFromAcidChestBoat() {
when(player.isInsideVehicle()).thenReturn(true);
Entity boat = mock(Entity.class);
when(boat.getType()).thenReturn(EntityType.CHEST_BOAT);
when(player.getVehicle()).thenReturn(boat);
assertTrue(ae.isSafeFromAcid(player));
}
/**
* Test method for {@link world.bentobox.acidisland.listeners.AcidEffect#isSafeFromAcid(Player)}.
*/
@Test
public void testIsSafeFromAcidFullArmor() {
when(settings.isFullArmorProtection()).thenReturn(true);
ItemStack[] armor = { new ItemStack(Material.CHAINMAIL_CHESTPLATE), new ItemStack(Material.CHAINMAIL_HELMET) };
when(inv.getArmorContents()).thenReturn(armor);
when(player.getInventory()).thenReturn(inv);
assertTrue(ae.isSafeFromAcid(player));
}
}