mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Prevent getSafeGroundLocation returning spots outside of the world border
This commit is contained in:
1 parent
4768793229
commit
70ed11fc65
1 file changed
+11
-2
@@ -407,12 +407,21 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
public CompletableFuture<Optional<Location>> getSafeGroundLocation(@NotNull Location location) {
|
public CompletableFuture<Optional<Location>> getSafeGroundLocation(@NotNull Location location) {
|
||||||
final CompletableFuture<Optional<Location>> future = new CompletableFuture<>();
|
final CompletableFuture<Optional<Location>> future = new CompletableFuture<>();
|
||||||
Bukkit.getScheduler().runTask(getInstance(), () -> BukkitAdapter.adaptLocation(location).ifPresentOrElse(
|
Bukkit.getScheduler().runTask(getInstance(), () -> BukkitAdapter.adaptLocation(location).ifPresentOrElse(
|
||||||
bukkitLocation -> PaperLib.getChunkAtAsync(bukkitLocation).thenAccept(chunk ->
|
bukkitLocation -> {
|
||||||
|
// Validate the location is within the world's border
|
||||||
|
assert bukkitLocation.getWorld() != null;
|
||||||
|
if (!bukkitLocation.getWorld().getWorldBorder().isInside(bukkitLocation)) {
|
||||||
|
future.complete(Optional.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find a safe position and return
|
||||||
|
PaperLib.getChunkAtAsync(bukkitLocation).thenAccept(chunk ->
|
||||||
future.complete(BukkitSafetyUtil.findSafeLocation(location.world, bukkitLocation,
|
future.complete(BukkitSafetyUtil.findSafeLocation(location.world, bukkitLocation,
|
||||||
chunk.getChunkSnapshot()))).exceptionally(throwable -> {
|
chunk.getChunkSnapshot()))).exceptionally(throwable -> {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}),
|
});
|
||||||
|
},
|
||||||
() -> future.complete(Optional.empty())));
|
() -> future.complete(Optional.empty())));
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user