Skip to content

Commit

Permalink
fix limits for simple entity limit
Browse files Browse the repository at this point in the history
  • Loading branch information
weaondara committed Apr 12, 2020
1 parent cc6781b commit 54cb8b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/world/bentobox/limits/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Settings(Limits addon) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,20 @@ private AtLimitResult atLimit(Island island, Entity ent) {
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())
Expand Down

0 comments on commit 54cb8b3

Please sign in to comment.