Compare commits

...

3 Commits

Author SHA1 Message Date
tastybento 466fafddea Adjust test to use latest API 2024-01-08 20:52:10 +09:00
tastybento 198cc66319 Prevent chest boats from causing acid damage.
Fixes #146. Added test classes too.
2024-01-08 20:33:32 +09:00
tastybento 40b382d878 Version 1.18.2 2024-01-08 19:46:19 +09:00
4 changed files with 62 additions and 8 deletions

View File

@ -65,7 +65,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.18.1</build.version>
<build.version>1.18.2</build.version>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_AcidIsland</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>

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

@ -67,7 +67,7 @@ import world.bentobox.bentobox.managers.RanksManager;
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Config.class, DatabaseSetup.class })
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Config.class, DatabaseSetup.class, RanksManager.class })
public class AcidIslandTest {
/**
@ -87,6 +87,8 @@ public class AcidIslandTest {
private FlagsManager fm;
@Mock
private Settings settings;
@Mock
private RanksManager rm;
private static AbstractDatabaseHandler<Object> h;
@ -131,6 +133,8 @@ public class AcidIslandTest {
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
Whitebox.setInternalState(RanksManager.class, "instance", rm);
// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
@ -203,10 +207,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));
}
}