Check for specific types and not classes
https://github.com/BentoBoxWorld/Limits/issues/105
This commit is contained in:
parent
d0e7ec0d68
commit
4f92611df0
|
@ -8,6 +8,7 @@ import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -15,7 +16,6 @@ import org.bukkit.entity.EntityType;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
|
@ -25,7 +25,6 @@ import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.limits.Limits;
|
import world.bentobox.limits.Limits;
|
||||||
import world.bentobox.limits.Settings;
|
|
||||||
import world.bentobox.limits.Settings.EntityGroup;
|
import world.bentobox.limits.Settings.EntityGroup;
|
||||||
import world.bentobox.limits.objects.IslandBlockCount;
|
import world.bentobox.limits.objects.IslandBlockCount;
|
||||||
|
|
||||||
|
|
|
@ -435,7 +435,8 @@ public class EntityLimitListener implements Listener {
|
||||||
// We have to count the entities
|
// We have to count the entities
|
||||||
if (limitAmount >= 0)
|
if (limitAmount >= 0)
|
||||||
{
|
{
|
||||||
int count = (int) ent.getWorld().getEntitiesByClasses(ent.getClass()).stream()
|
int count = (int) ent.getWorld().getEntities().stream()
|
||||||
|
.filter(e -> e.getType().equals(ent.getType()))
|
||||||
.filter(e -> island.inIslandSpace(e.getLocation()))
|
.filter(e -> island.inIslandSpace(e.getLocation()))
|
||||||
.count();
|
.count();
|
||||||
if (count >= limitAmount)
|
if (count >= limitAmount)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -48,7 +48,7 @@ public class EntityLimitListenerTest {
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
@Mock
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
private Collection<Entity> collection;
|
private List<Entity> collection;
|
||||||
@Mock
|
@Mock
|
||||||
private Location location;
|
private Location location;
|
||||||
private IslandBlockCount ibc;
|
private IslandBlockCount ibc;
|
||||||
|
@ -81,7 +81,7 @@ public class EntityLimitListenerTest {
|
||||||
collection.add(ent);
|
collection.add(ent);
|
||||||
collection.add(ent);
|
collection.add(ent);
|
||||||
collection.add(ent);
|
collection.add(ent);
|
||||||
when(world.getEntitiesByClasses(any())).thenReturn(collection);
|
when(world.getEntities()).thenReturn(collection);
|
||||||
|
|
||||||
ell = new EntityLimitListener(addon);
|
ell = new EntityLimitListener(addon);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue