Prioritize finale center when searching for safe locations in /stuck command

This commit is contained in:
akastijn 2026-06-27 23:58:54 +02:00
parent 1a9f4cbd2d
commit 38f8ffd4a3

View File

@ -155,18 +155,28 @@ 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);
Optional<Location> safeY = findSafeY(baseLocation);
if (safeY.isPresent()) {
return safeY;
}
if (prioritizeFinale) {
candidates.sort(Comparator.comparingDouble(loc -> loc.distanceSquared(finaleCenter)));
}
for (Location baseLocation : candidates) {
Optional<Location> safeY = findSafeY(baseLocation);
if (safeY.isPresent()) {
return safeY;
}
}
}