mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
TeleportResult refactor, use record and bundle resolved information, separate TeleportState enum, deprecate relevant API
This commit is contained in:
1 parent
82d47f0878
commit
4164f07841
12 files changed
+285
-151
No files matched your search
@@ -101,24 +101,24 @@ public class BukkitPlayer extends OnlineUser {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<TeleportResult> teleportLocally(@NotNull Location location, boolean asynchronous) {
|
||||
public CompletableFuture<TeleportResult.ResultState> teleportLocally(@NotNull Location location, boolean asynchronous) {
|
||||
final Optional<org.bukkit.Location> bukkitLocation = BukkitAdapter.adaptLocation(location);
|
||||
if (bukkitLocation.isEmpty()) {
|
||||
return CompletableFuture.completedFuture(TeleportResult.FAILED_INVALID_WORLD);
|
||||
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_INVALID_WORLD);
|
||||
}
|
||||
assert bukkitLocation.get().getWorld() != null;
|
||||
if (!bukkitLocation.get().getWorld().getWorldBorder().isInside(bukkitLocation.get())) {
|
||||
return CompletableFuture.completedFuture(TeleportResult.FAILED_ILLEGAL_COORDINATES);
|
||||
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_ILLEGAL_COORDINATES);
|
||||
}
|
||||
final CompletableFuture<TeleportResult> resultCompletableFuture = new CompletableFuture<>();
|
||||
final CompletableFuture<TeleportResult.ResultState> resultCompletableFuture = new CompletableFuture<>();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (asynchronous) {
|
||||
PaperLib.teleportAsync(player, bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.PLUGIN)
|
||||
.thenAccept(result -> resultCompletableFuture.complete(
|
||||
result ? TeleportResult.COMPLETED_LOCALLY : TeleportResult.FAILED_INVALID_WORLD));
|
||||
result ? TeleportResult.ResultState.COMPLETED_LOCALLY : TeleportResult.ResultState.FAILED_INVALID_WORLD));
|
||||
} else {
|
||||
player.teleport(bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
resultCompletableFuture.complete(TeleportResult.COMPLETED_LOCALLY);
|
||||
resultCompletableFuture.complete(TeleportResult.ResultState.COMPLETED_LOCALLY);
|
||||
}
|
||||
});
|
||||
return resultCompletableFuture;
|
||||
|
||||
Reference in new issue
Block a user