Lambda cleanup

This commit is contained in:
TheMode 2021-07-24 04:31:35 +02:00
parent f7d30feb7f
commit 19e3bee23c
2 changed files with 25 additions and 26 deletions

View File

@ -823,6 +823,10 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
this.gravityAcceleration = gravityAcceleration;
}
public double getDistance(@NotNull Point point) {
return getPosition().distance(point);
}
/**
* Gets the distance between two entities.
*
@ -830,7 +834,7 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
* @return the distance between this and {@code entity}
*/
public double getDistance(@NotNull Entity entity) {
return getPosition().distance(entity.getPosition());
return getDistance(entity.getPosition());
}
/**

View File

@ -149,10 +149,9 @@ public class EntityFinder {
if (distance != null) {
final int minDistance = distance.getMinimum();
final int maxDistance = distance.getMaximum();
result = result.stream().filter(entity -> {
final int distance = (int) entity.getPosition().distance(pos);
return MathUtils.isBetween(distance, minDistance, maxDistance);
}).collect(Collectors.toList());
result = result.stream()
.filter(entity -> MathUtils.isBetween(entity.getDistance(pos), minDistance, maxDistance))
.collect(Collectors.toList());
}
// Diff X/Y/Z
@ -180,46 +179,42 @@ public class EntityFinder {
// Entity type
if (!entityTypes.isEmpty()) {
result = result.stream().filter(entity ->
filterToggleableMap(entity.getEntityType(), entityTypes))
result = result.stream()
.filter(entity -> filterToggleableMap(entity.getEntityType(), entityTypes))
.collect(Collectors.toList());
}
// GameMode
if (!gameModes.isEmpty()) {
result = result.stream().filter(entity -> {
if (!(entity instanceof Player))
return false;
return filterToggleableMap(((Player) entity).getGameMode(), gameModes);
}).collect(Collectors.toList());
result = result.stream()
.filter(Player.class::isInstance)
.filter(entity -> filterToggleableMap(((Player) entity).getGameMode(), gameModes))
.collect(Collectors.toList());
}
// Level
if (level != null) {
final int minLevel = level.getMinimum();
final int maxLevel = level.getMaximum();
result = result.stream().filter(entity -> {
if (!(entity instanceof Player))
return false;
final int level = ((Player) entity).getLevel();
return MathUtils.isBetween(level, minLevel, maxLevel);
}).collect(Collectors.toList());
result = result.stream()
.filter(Player.class::isInstance)
.filter(entity -> MathUtils.isBetween(((Player) entity).getLevel(), minLevel, maxLevel))
.collect(Collectors.toList());
}
// Name
if (!names.isEmpty()) {
result = result.stream().filter(entity -> {
if (!(entity instanceof Player))
return false;
return filterToggleableMap(((Player) entity).getUsername(), names);
}).collect(Collectors.toList());
result = result.stream()
.filter(Player.class::isInstance)
.filter(entity -> filterToggleableMap(((Player) entity).getUsername(), names))
.collect(Collectors.toList());
}
// UUID
if (!uuids.isEmpty()) {
result = result.stream().filter(entity ->
filterToggleableMap(entity.getUuid(), uuids)).collect(Collectors.toList());
result = result.stream()
.filter(entity -> filterToggleableMap(entity.getUuid(), uuids))
.collect(Collectors.toList());
}