From 5874b3bcad294d1130ced2cd41c98609ea276fa1 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 5 Apr 2020 17:15:08 -0400 Subject: [PATCH] More performance improvements. --- .../com/songoda/ultimatestacker/tasks/StackingTask.java | 8 +++++--- .../com/songoda/ultimatestacker/utils/EntityUtils.java | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java index 17291f5..5e2647b 100644 --- a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java +++ b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java @@ -146,9 +146,11 @@ public class StackingTask extends BukkitRunnable { int maxEntityStackSize = getEntityStackSize(livingEntity); // Get similar entities around our entity and make sure those entities are both compatible and stackable. - List stackableFriends = plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location) - .stream().filter(entity -> isEntityStackable(entity, location)) - .collect(Collectors.toCollection(LinkedList::new)); + List stackableFriends = new LinkedList<>(); + for (LivingEntity entity : plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location)) { + if (!isEntityStackable(entity, location)) continue; + stackableFriends.add(entity); + } // Loop through our similar stackable entities. for (LivingEntity entity : stackableFriends) { diff --git a/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java b/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java index 57c2617..7497071 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/EntityUtils.java @@ -254,9 +254,12 @@ public class EntityUtils { public List getSimilarEntitiesAroundEntity(LivingEntity initialEntity, Location location) { // Create a list of all entities around the initial entity of the same type. - List entityList = getNearbyEntities(location, searchRadius, stackWholeChunk) - .stream().filter(entity -> entity.getType() == initialEntity.getType() && entity != initialEntity) - .collect(Collectors.toCollection(LinkedList::new)); + List entityList = new LinkedList<>(); + for (LivingEntity entity : getNearbyEntities(location, searchRadius, stackWholeChunk)) { + if (entity.getType() != initialEntity.getType() || entity == initialEntity) + continue; + entityList.add(entity); + } if (stackFlyingDown && Methods.canFly(initialEntity)) entityList.removeIf(entity -> entity.getLocation().getY() > initialEntity.getLocation().getY());