fix limits for simple entity limit

This commit is contained in:
wea_ondara 2020-04-12 14:39:19 +02:00
parent cc6781bf44
commit 54cb8b3a10
2 changed files with 10 additions and 7 deletions

View File

@ -98,7 +98,7 @@ public class Settings {
}
addon.log("Entity group limits:");
getGroupLimitDefinitions().stream().map(e -> "Limit " + e.getName() + " to " + e.getLimit()).forEach(addon::log);
getGroupLimitDefinitions().stream().map(e -> "Limit " + e.getName() + " (" + e.getTypes().stream().map(x -> x.name()).collect(Collectors.joining(", ")) + ") to " + e.getLimit()).forEach(addon::log);
}
private EntityType getType(String key) {

View File

@ -217,17 +217,20 @@ public class EntityLimitListener implements Listener {
if (limitAmount < 0 && groupsLimits.isEmpty()) return new AtLimitResult();
// We have to count the entities
int count = (int) ent.getWorld().getEntities().stream()
.filter(e -> e.getType().equals(ent.getType()))
.filter(e -> island.inIslandSpace(e.getLocation())).count();
if (count >= limitAmount)
return new AtLimitResult(ent.getType(), limitAmount);
if (limitAmount >= 0)
{
int count = (int) ent.getWorld().getEntities().stream()
.filter(e -> e.getType().equals(ent.getType()))
.filter(e -> island.inIslandSpace(e.getLocation())).count();
if (count >= limitAmount)
return new AtLimitResult(ent.getType(), limitAmount);
}
// Now do the group limits
for (Map.Entry<Settings.EntityGroup, Integer> group : groupsLimits.entrySet()) { //do not use lambda
if (group.getValue() < 0)
continue;
count = (int) ent.getWorld().getEntities().stream()
int count = (int) ent.getWorld().getEntities().stream()
.filter(e -> group.getKey().contains(e.getType()))
.filter(e -> island.inIslandSpace(e.getLocation())).count();
if (count >= group.getValue())