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