huge performance boost for entity limit

This commit is contained in:
evlad 2022-11-07 02:05:09 +01:00
parent f726492eae
commit 97006d28c1
1 changed files with 10 additions and 4 deletions

View File

@ -403,9 +403,12 @@ public class EntityLimitListener implements Listener {
// We have to count the entities
if (limitAmount >= 0)
{
int count = (int) ent.getWorld().getEntities().stream()
// int count = (int) ent.getWorld().getEntities().stream()
// .filter(e -> e.getType().equals(ent.getType()))
// .filter(e -> island.inIslandSpace(e.getLocation()))
// .count();
int count = (int) ent.getWorld().getNearbyEntities(island.getBoundingBox()).stream()
.filter(e -> e.getType().equals(ent.getType()))
.filter(e -> island.inIslandSpace(e.getLocation()))
.count();
int max = limitAmount + (ibc == null ? 0 : ibc.getEntityLimitOffset(ent.getType()));
if (count >= max) {
@ -424,9 +427,12 @@ public class EntityLimitListener implements Listener {
for (Map.Entry<Settings.EntityGroup, Integer> group : groupsLimits.entrySet()) { //do not use lambda
if (group.getValue() < 0)
continue;
int 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();
int count = (int) ent.getWorld().getNearbyEntities(island.getBoundingBox()).stream()
.filter(e -> group.getKey().contains(e.getType()))
.filter(e -> island.inIslandSpace(e.getLocation())).count();
.count();
int max = group.getValue() + + (ibc == null ? 0 : ibc.getEntityGroupLimitOffset(group.getKey().getName()));
if (count >= max) {
return new AtLimitResult(group.getKey(), max);