Fixes IslandsManager test cases and pufferfish removal

The clear area method should not remove pufferfish as per
https://github.com/BentoBoxWorld/BentoBox/pull/595
This commit is contained in:
tastybento 2019-03-09 16:54:54 -08:00
parent 16388e4721
commit 8f24e59a21
2 changed files with 13 additions and 3 deletions

View File

@ -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);
}

View File

@ -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<Entity> 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();
}
/**