diff --git a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java index f69e3b4a9..43d103be5 100644 --- a/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/IslandsManager.java @@ -23,6 +23,7 @@ import org.bukkit.block.data.Openable; import org.bukkit.entity.Boat; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.entity.PufferFish; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; import org.eclipse.jdt.annotation.NonNull; @@ -941,7 +942,9 @@ public class IslandsManager { */ public void clearArea(Location loc) { loc.getWorld().getNearbyEntities(loc, 5D, 5D, 5D).stream() - .filter(en -> Util.isHostileEntity(en) && !plugin.getIWM().getRemoveMobsWhitelist(loc.getWorld()).contains(en.getType())) + .filter(en -> Util.isHostileEntity(en) + && !plugin.getIWM().getRemoveMobsWhitelist(loc.getWorld()).contains(en.getType()) + && !(en instanceof PufferFish)) .forEach(Entity::remove); } diff --git a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java index 31ff1dd7a..d23d691e3 100644 --- a/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java +++ b/src/test/java/world/bentobox/bentobox/managers/IslandsManagerTest.java @@ -35,6 +35,7 @@ import org.bukkit.entity.Creeper; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.entity.PufferFish; import org.bukkit.entity.Slime; import org.bukkit.entity.Wither; import org.bukkit.entity.Zombie; @@ -186,6 +187,9 @@ public class IslandsManagerTest { // Addon when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty()); + // Cover hostile entities + when(Util.isHostileEntity(Mockito.any())).thenCallRealMethod(); + } @@ -1078,7 +1082,8 @@ public class IslandsManagerTest { when(wither.getType()).thenReturn(EntityType.WITHER); Creeper creeper = mock(Creeper.class); when(creeper.getType()).thenReturn(EntityType.CREEPER); - + PufferFish pufferfish = mock(PufferFish.class); + when(pufferfish.getType()).thenReturn(EntityType.PUFFERFISH); Collection collection = new ArrayList<>(); collection.add(player); @@ -1087,6 +1092,7 @@ public class IslandsManagerTest { collection.add(slime); collection.add(wither); collection.add(creeper); + collection.add(pufferfish); when(world .getNearbyEntities(Mockito.any(Location.class), Mockito.anyDouble(), Mockito.anyDouble(), Mockito.anyDouble())) .thenReturn(collection); @@ -1097,9 +1103,10 @@ public class IslandsManagerTest { Mockito.verify(zombie).remove(); Mockito.verify(player, Mockito.never()).remove(); Mockito.verify(cow, Mockito.never()).remove(); - Mockito.verify(slime, Mockito.never()).remove(); + Mockito.verify(slime).remove(); Mockito.verify(wither, Mockito.never()).remove(); Mockito.verify(creeper).remove(); + Mockito.verify(pufferfish, Mockito.never()).remove(); } /**