Prioritize finale center when searching for safe locations in /stuck command
This commit is contained in:
parent
1a9f4cbd2d
commit
38f8ffd4a3
|
|
@ -155,21 +155,31 @@ public class Stuck extends SubCommand implements Listener {
|
|||
|
||||
private Optional<Location> findSafeLocation(Location start) {
|
||||
int radius = 10;
|
||||
Location finaleCenter = Config.DESTINATION.FINALE_CENTER;
|
||||
boolean prioritizeFinale = finaleCenter != null && finaleCenter.getWorld().equals(start.getWorld());
|
||||
|
||||
for (int r = 0; r <= radius; r++) {
|
||||
List<Location> candidates = new ArrayList<>();
|
||||
for (int x = -r; x <= r; x++) {
|
||||
for (int z = -r; z <= r; z++) {
|
||||
if (Math.abs(x) != r && Math.abs(z) != r) {
|
||||
continue;
|
||||
}
|
||||
candidates.add(start.clone().add(x, 0, z));
|
||||
}
|
||||
}
|
||||
|
||||
Location baseLocation = start.clone().add(x, 0, z);
|
||||
if (prioritizeFinale) {
|
||||
candidates.sort(Comparator.comparingDouble(loc -> loc.distanceSquared(finaleCenter)));
|
||||
}
|
||||
|
||||
for (Location baseLocation : candidates) {
|
||||
Optional<Location> safeY = findSafeY(baseLocation);
|
||||
if (safeY.isPresent()) {
|
||||
return safeY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user