More performance improvements.

This commit is contained in:
Brianna 2020-04-05 17:15:08 -04:00
parent d229e65388
commit 5874b3bcad
2 changed files with 11 additions and 6 deletions

View File

@ -146,9 +146,11 @@ public class StackingTask extends BukkitRunnable {
int maxEntityStackSize = getEntityStackSize(livingEntity); int maxEntityStackSize = getEntityStackSize(livingEntity);
// Get similar entities around our entity and make sure those entities are both compatible and stackable. // Get similar entities around our entity and make sure those entities are both compatible and stackable.
List<LivingEntity> stackableFriends = plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location) List<LivingEntity> stackableFriends = new LinkedList<>();
.stream().filter(entity -> isEntityStackable(entity, location)) for (LivingEntity entity : plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location)) {
.collect(Collectors.toCollection(LinkedList::new)); if (!isEntityStackable(entity, location)) continue;
stackableFriends.add(entity);
}
// Loop through our similar stackable entities. // Loop through our similar stackable entities.
for (LivingEntity entity : stackableFriends) { for (LivingEntity entity : stackableFriends) {

View File

@ -254,9 +254,12 @@ public class EntityUtils {
public List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initialEntity, Location location) { public List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initialEntity, Location location) {
// Create a list of all entities around the initial entity of the same type. // Create a list of all entities around the initial entity of the same type.
List<LivingEntity> entityList = getNearbyEntities(location, searchRadius, stackWholeChunk) List<LivingEntity> entityList = new LinkedList<>();
.stream().filter(entity -> entity.getType() == initialEntity.getType() && entity != initialEntity) for (LivingEntity entity : getNearbyEntities(location, searchRadius, stackWholeChunk)) {
.collect(Collectors.toCollection(LinkedList::new)); if (entity.getType() != initialEntity.getType() || entity == initialEntity)
continue;
entityList.add(entity);
}
if (stackFlyingDown && Methods.canFly(initialEntity)) if (stackFlyingDown && Methods.canFly(initialEntity))
entityList.removeIf(entity -> entity.getLocation().getY() > initialEntity.getLocation().getY()); entityList.removeIf(entity -> entity.getLocation().getY() > initialEntity.getLocation().getY());