TeleportResult refactor, use record and bundle resolved information, separate TeleportState enum, deprecate relevant API

This commit is contained in:
William committed 2022-10-19 01:12:19 +01:00
1 parent 82d47f0878
commit 4164f07841
12 files changed
+285 -151

No files matched your search

@@ -9,8 +9,8 @@ import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.position.*;
import net.william278.huskhomes.teleport.Teleport;
import net.william278.huskhomes.teleport.TeleportBuilder;
import net.william278.huskhomes.teleport.TeleportResult;
import net.william278.huskhomes.random.RandomTeleportEngine;
import net.william278.huskhomes.teleport.TeleportResult;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -343,17 +343,19 @@ public abstract class BaseHuskHomesAPI {
* @param position The {@link Position} to teleport the user to
* @param timedTeleport Whether the teleport should be timed or not (requiring a warmup where they must stand still
* for a period of time)
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult.ResultState#successful} will be {@code true}.
* @since 3.0
* @deprecated Use {@link #teleportBuilder(OnlineUser)} to construct a teleport
*/
public final CompletableFuture<TeleportResult> teleportPlayer(@NotNull OnlineUser user,
@NotNull Position position,
final boolean timedTeleport) {
@Deprecated(since = "3.1")
public final CompletableFuture<TeleportResult.ResultState> teleportPlayer(@NotNull OnlineUser user,
@NotNull Position position,
final boolean timedTeleport) {
final TeleportBuilder builder = teleportBuilder(user).setTarget(position);
return timedTeleport
? builder.toTimedTeleport().thenApplyAsync(teleport -> teleport.execute().join())
: builder.toTeleport().thenApplyAsync(teleport -> teleport.execute().join());
? builder.toTimedTeleport().thenApplyAsync(teleport -> teleport.execute().join().getState())
: builder.toTeleport().thenApplyAsync(teleport -> teleport.execute().join().getState());
}
/**
@@ -361,11 +363,13 @@ public abstract class BaseHuskHomesAPI {
*
* @param user The {@link OnlineUser} to teleport
* @param position The {@link Position} to teleport the user to
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult.ResultState#successful} will be {@code true}.
* @since 3.0
* @deprecated Use {@link #teleportBuilder(OnlineUser)} to construct a teleport
*/
public final CompletableFuture<TeleportResult> teleportPlayer(@NotNull OnlineUser user, @NotNull Position position) {
@Deprecated(since = "3.1")
public final CompletableFuture<TeleportResult.ResultState> teleportPlayer(@NotNull OnlineUser user, @NotNull Position position) {
return teleportPlayer(user, position, false);
}
@@ -377,20 +381,27 @@ public abstract class BaseHuskHomesAPI {
* @param timedTeleport Whether the teleport should be timed or not (requiring a warmup where they must stand still
* for a period of time)
* @param rtpArgs Arguments that will be passed to the implementing {@link RandomTeleportEngine}
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult.ResultState#successful} will be {@code true}.
* @since 3.0
*/
public final CompletableFuture<TeleportResult> randomlyTeleportPlayer(@NotNull OnlineUser user,
final boolean timedTeleport,
@NotNull String... rtpArgs) {
public final CompletableFuture<TeleportResult.ResultState> randomlyTeleportPlayer(@NotNull OnlineUser user,
final boolean timedTeleport,
@NotNull String... rtpArgs) {
return CompletableFuture.supplyAsync(() -> plugin.getRandomTeleportEngine()
.getRandomPosition(user, rtpArgs)
.thenApply(position -> {
if (position.isPresent()) {
return teleportPlayer(user, position.get(), timedTeleport).join();
final TeleportBuilder builder = Teleport.builder(plugin, user)
.setTarget(position.get());
return timedTeleport
? builder.toTimedTeleport()
.thenApplyAsync(teleport -> teleport.execute().join().getState()).join()
: builder.toTeleport()
.thenApplyAsync(teleport -> teleport.execute().join().getState()).join();
} else {
return TeleportResult.CANCELLED;
return TeleportResult.ResultState.CANCELLED;
}
}).join());
}
@@ -400,11 +411,11 @@ public abstract class BaseHuskHomesAPI {
* generated by the current {@link RandomTeleportEngine}
*
* @param user The {@link OnlineUser} to teleport
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of
* completing the teleport. If the teleport was successful, the {@link TeleportResult.ResultState#successful} will be {@code true}.
* @since 3.0
*/
public final CompletableFuture<TeleportResult> randomlyTeleportPlayer(@NotNull OnlineUser user) {
public final CompletableFuture<TeleportResult.ResultState> randomlyTeleportPlayer(@NotNull OnlineUser user) {
return randomlyTeleportPlayer(user, false);
}