Skip to content

Commit

Permalink
Prevent chest boats from causing acid damage.
Browse files Browse the repository at this point in the history
Fixes #146. Added test classes too.
  • Loading branch information
tastybento committed Jan 8, 2024
1 parent 40b382d commit 198cc66
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private boolean isSafeFromRain(Player player) {
* @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
Expand All @@ -275,7 +275,8 @@ private boolean isSafeFromAcid(Player player) {
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;
}
Expand Down
6 changes: 0 additions & 6 deletions src/test/java/world/bentobox/acidisland/AcidIslandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
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
Expand Down Expand Up @@ -202,11 +201,6 @@ public void setUp() throws Exception {

// Settings
when(plugin.getSettings()).thenReturn(settings);

// RanksManager
RanksManager rm = new RanksManager();
when(plugin.getRanksManager()).thenReturn(rm);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,4 +648,57 @@ public void testCheckForRainWetPlayer() {
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));
}

}

0 comments on commit 198cc66

Please sign in to comment.