Avoids counting entities if the type spawned is not limited.

https://github.com/BentoBoxWorld/Limits/issues/74
This commit is contained in:
tastybento 2020-03-25 21:00:37 -07:00
parent 55bb288dad
commit 4cb061d594
2 changed files with 6 additions and 6 deletions

View File

@ -64,7 +64,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.9.2</build.version>
<build.version>1.9.3</build.version>
</properties>
<!-- Profiles will allow to automatically change build version. -->

View File

@ -164,9 +164,6 @@ public class EntityLimitListener implements Listener {
* @return true if at the limit, false if not
*/
private boolean atLimit(Island island, Entity ent) {
long count = ent.getWorld().getEntities().stream()
.filter(e -> e.getType().equals(ent.getType()))
.filter(e -> island.inIslandSpace(e.getLocation())).count();
// Check island settings first
int limitAmount = -1;
if (addon.getBlockLimitListener().getIsland(island.getUniqueId()) != null) {
@ -176,8 +173,11 @@ public class EntityLimitListener implements Listener {
if (limitAmount < 0 && addon.getSettings().getLimits().containsKey(ent.getType())) {
limitAmount = addon.getSettings().getLimits().get(ent.getType());
}
if (limitAmount == -1) return false;
return count >= limitAmount;
if (limitAmount < 0) return false;
// We have to count the entities
return ent.getWorld().getEntities().stream()
.filter(e -> e.getType().equals(ent.getType()))
.filter(e -> island.inIslandSpace(e.getLocation())).count() >= limitAmount;
}
}