Fix API back-compat; rename new result class to CompletedTeleport and move enum TeleportResult back to upper

This commit is contained in:
William committed 2022-10-19 01:27:06 +01:00
1 parent f9b04f8fbc
commit 681a74213c
8 files changed
+174 -164

No files matched your search

@@ -101,24 +101,24 @@ public class BukkitPlayer extends OnlineUser {
} }
@Override @Override
public CompletableFuture<TeleportResult.ResultState> teleportLocally(@NotNull Location location, boolean asynchronous) { public CompletableFuture<TeleportResult> teleportLocally(@NotNull Location location, boolean asynchronous) {
final Optional<org.bukkit.Location> bukkitLocation = BukkitAdapter.adaptLocation(location); final Optional<org.bukkit.Location> bukkitLocation = BukkitAdapter.adaptLocation(location);
if (bukkitLocation.isEmpty()) { if (bukkitLocation.isEmpty()) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_INVALID_WORLD); return CompletableFuture.completedFuture(TeleportResult.FAILED_INVALID_WORLD);
} }
assert bukkitLocation.get().getWorld() != null; assert bukkitLocation.get().getWorld() != null;
if (!bukkitLocation.get().getWorld().getWorldBorder().isInside(bukkitLocation.get())) { if (!bukkitLocation.get().getWorld().getWorldBorder().isInside(bukkitLocation.get())) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_ILLEGAL_COORDINATES); return CompletableFuture.completedFuture(TeleportResult.FAILED_ILLEGAL_COORDINATES);
} }
final CompletableFuture<TeleportResult.ResultState> resultCompletableFuture = new CompletableFuture<>(); final CompletableFuture<TeleportResult> resultCompletableFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTask(plugin, () -> { Bukkit.getScheduler().runTask(plugin, () -> {
if (asynchronous) { if (asynchronous) {
PaperLib.teleportAsync(player, bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.PLUGIN) PaperLib.teleportAsync(player, bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.PLUGIN)
.thenAccept(result -> resultCompletableFuture.complete( .thenAccept(result -> resultCompletableFuture.complete(
result ? TeleportResult.ResultState.COMPLETED_LOCALLY : TeleportResult.ResultState.FAILED_INVALID_WORLD)); result ? TeleportResult.COMPLETED_LOCALLY : TeleportResult.FAILED_INVALID_WORLD));
} else { } else {
player.teleport(bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.PLUGIN); player.teleport(bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.PLUGIN);
resultCompletableFuture.complete(TeleportResult.ResultState.COMPLETED_LOCALLY); resultCompletableFuture.complete(TeleportResult.COMPLETED_LOCALLY);
} }
}); });
return resultCompletableFuture; return resultCompletableFuture;
@@ -343,13 +343,13 @@ public abstract class BaseHuskHomesAPI {
* @param position The {@link Position} to teleport the user to * @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 * @param timedTeleport Whether the teleport should be timed or not (requiring a warmup where they must stand still
* for a period of time) * for a period of time)
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of * @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.ResultState#successful} will be {@code true}. * completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @since 3.0 * @since 3.0
* @deprecated Use {@link #teleportBuilder(OnlineUser)} to construct a teleport * @deprecated Use {@link #teleportBuilder(OnlineUser)} to construct a teleport
*/ */
@Deprecated(since = "3.1") @Deprecated(since = "3.1")
public final CompletableFuture<TeleportResult.ResultState> teleportPlayer(@NotNull OnlineUser user, public final CompletableFuture<TeleportResult> teleportPlayer(@NotNull OnlineUser user,
@NotNull Position position, @NotNull Position position,
final boolean timedTeleport) { final boolean timedTeleport) {
final TeleportBuilder builder = teleportBuilder(user).setTarget(position); final TeleportBuilder builder = teleportBuilder(user).setTarget(position);
@@ -363,13 +363,13 @@ public abstract class BaseHuskHomesAPI {
* *
* @param user The {@link OnlineUser} to teleport * @param user The {@link OnlineUser} to teleport
* @param position The {@link Position} to teleport the user to * @param position The {@link Position} to teleport the user to
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of * @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.ResultState#successful} will be {@code true}. * completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @since 3.0 * @since 3.0
* @deprecated Use {@link #teleportBuilder(OnlineUser)} to construct a teleport * @deprecated Use {@link #teleportBuilder(OnlineUser)} to construct a teleport
*/ */
@Deprecated(since = "3.1") @Deprecated(since = "3.1")
public final CompletableFuture<TeleportResult.ResultState> teleportPlayer(@NotNull OnlineUser user, @NotNull Position position) { public final CompletableFuture<TeleportResult> teleportPlayer(@NotNull OnlineUser user, @NotNull Position position) {
return teleportPlayer(user, position, false); return teleportPlayer(user, position, false);
} }
@@ -381,11 +381,11 @@ public abstract class BaseHuskHomesAPI {
* @param timedTeleport Whether the teleport should be timed or not (requiring a warmup where they must stand still * @param timedTeleport Whether the teleport should be timed or not (requiring a warmup where they must stand still
* for a period of time) * for a period of time)
* @param rtpArgs Arguments that will be passed to the implementing {@link RandomTeleportEngine} * @param rtpArgs Arguments that will be passed to the implementing {@link RandomTeleportEngine}
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of * @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.ResultState#successful} will be {@code true}. * completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @since 3.0 * @since 3.0
*/ */
public final CompletableFuture<TeleportResult.ResultState> randomlyTeleportPlayer(@NotNull OnlineUser user, public final CompletableFuture<TeleportResult> randomlyTeleportPlayer(@NotNull OnlineUser user,
final boolean timedTeleport, final boolean timedTeleport,
@NotNull String... rtpArgs) { @NotNull String... rtpArgs) {
return CompletableFuture.supplyAsync(() -> plugin.getRandomTeleportEngine() return CompletableFuture.supplyAsync(() -> plugin.getRandomTeleportEngine()
@@ -401,7 +401,7 @@ public abstract class BaseHuskHomesAPI {
: builder.toTeleport() : builder.toTeleport()
.thenApplyAsync(teleport -> teleport.execute().join().getState()).join(); .thenApplyAsync(teleport -> teleport.execute().join().getState()).join();
} else { } else {
return TeleportResult.ResultState.CANCELLED; return TeleportResult.CANCELLED;
} }
}).join()); }).join());
} }
@@ -411,11 +411,11 @@ public abstract class BaseHuskHomesAPI {
* generated by the current {@link RandomTeleportEngine} * generated by the current {@link RandomTeleportEngine}
* *
* @param user The {@link OnlineUser} to teleport * @param user The {@link OnlineUser} to teleport
* @return A {@link CompletableFuture} that will complete with a {@link TeleportResult.ResultState} indicating the result of * @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.ResultState#successful} will be {@code true}. * completing the teleport. If the teleport was successful, the {@link TeleportResult#successful} will be {@code true}.
* @since 3.0 * @since 3.0
*/ */
public final CompletableFuture<TeleportResult.ResultState> randomlyTeleportPlayer(@NotNull OnlineUser user) { public final CompletableFuture<TeleportResult> randomlyTeleportPlayer(@NotNull OnlineUser user) {
return randomlyTeleportPlayer(user, false); return randomlyTeleportPlayer(user, false);
} }
@@ -23,7 +23,7 @@ public class MessagePayload {
*/ */
@Nullable @Nullable
@SerializedName("teleport_result") @SerializedName("teleport_result")
public TeleportResult.ResultState resultState; public TeleportResult resultState;
/** /**
* A teleport request field * A teleport request field
@@ -56,13 +56,13 @@ public class MessagePayload {
} }
/** /**
* Returns a payload containing a {@link TeleportResult.ResultState} * Returns a payload containing a {@link TeleportResult}
* *
* @param resultState the teleport to send * @param resultState the teleport to send
* @return a payload containing the teleport result * @return a payload containing the teleport result
*/ */
@NotNull @NotNull
public static MessagePayload withTeleportResult(@NotNull TeleportResult.ResultState resultState) { public static MessagePayload withTeleportResult(@NotNull TeleportResult resultState) {
final MessagePayload payload = new MessagePayload(); final MessagePayload payload = new MessagePayload();
payload.resultState = resultState; payload.resultState = resultState;
return payload; return payload;
@@ -144,7 +144,7 @@ public abstract class OnlineUser extends User {
* @param location the {@link Location} to teleport the player to * @param location the {@link Location} to teleport the player to
* @param asynchronous if the teleport should be asynchronous * @param asynchronous if the teleport should be asynchronous
*/ */
public abstract CompletableFuture<TeleportResult.ResultState> teleportLocally(@NotNull Location location, boolean asynchronous); public abstract CompletableFuture<TeleportResult> teleportLocally(@NotNull Location location, boolean asynchronous);
/** /**
* Returns if a player is moving (i.e. they have momentum) * Returns if a player is moving (i.e. they have momentum)
@@ -0,0 +1,117 @@
package net.william278.huskhomes.teleport;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.position.Position;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
/**
* Represents the result of executing a {@link Teleport} or {@link TimedTeleport}
*
* @since 3.1
*/
public class CompletedTeleport {
/**
* The state of the {@link Teleport}
*/
@NotNull
private final TeleportResult state;
/**
* The {@link User} who is doing the teleporting
*/
@Nullable
private final User teleporter;
/**
* The {@link Position} the teleporter should be teleported to
*/
@Nullable
private final Position destination;
/**
* <b>Internal</b> - Create a new {@link CompletedTeleport} (use {@link #from(TeleportResult, Teleport)})
*
* @param state The {@link TeleportResult} of completing the teleport
* @param teleporter The {@link User} who is doing the teleporting
* @param destination The {@link Position} the teleporter should be teleported to
* @since 3.1
*/
private CompletedTeleport(@NotNull TeleportResult state, @Nullable User teleporter, @Nullable Position destination) {
this.state = state;
this.teleporter = teleporter;
this.destination = destination;
}
/**
* Create a new {@link CompletedTeleport} for a {@link Teleport} with an outcome {@link TeleportResult}
*
* @param state The outcome {@link TeleportResult}
* @param teleport The {@link Teleport} that was executed
* @return The {@link CompletedTeleport} of executing the supplied {@link Teleport}
* @since 3.1
*/
public static CompletedTeleport from(@NotNull TeleportResult state, @NotNull Teleport teleport) {
return new CompletedTeleport(state, teleport.teleporter, teleport.target);
}
/**
* Get the state of the {@link Teleport} after execution has finished
*
* @return The {@link TeleportResult} of the teleport
* @since 3.1
*/
@NotNull
public TeleportResult getState() {
return state;
}
/**
* Returns if the teleport was successful
*
* @return {@code true} if the teleport was successful, {@code false} otherwise
* @since 3.1
*/
public boolean successful() {
return state.successful;
}
/**
* Get the {@link User} who is doing the teleporting
*
* @return The teleporter, if they were resolved
* @implNote The optional will return empty if the state is {@link TeleportResult#FAILED_TELEPORTER_NOT_RESOLVED}
* @since 3.1
*/
public Optional<User> getTeleporter() {
return Optional.ofNullable(teleporter);
}
/**
* Get the target {@link Position} the teleporter should have been teleported to
*
* @return The target position, if it was resolved
* @implNote The optional will return empty if the state is {@link TeleportResult#FAILED_TARGET_NOT_RESOLVED}
* @since 3.1
*/
public Optional<Position> getDestination() {
return Optional.ofNullable(destination);
}
/**
* Send an {@link OnlineUser} the corresponding message indicating the state of the teleport once it has executred
*
* @param locales the {@link Locales} instance to use
* @param user the {@link OnlineUser} to send the message to
* @since 3.1
*/
public void sendResultMessage(@NotNull Locales locales, @NotNull OnlineUser user) {
this.state.sendResultMessage(locales, user);
}
}
@@ -92,30 +92,30 @@ public class Teleport {
* *
* @return A {@link CompletableFuture} that completes when the teleport is finished * @return A {@link CompletableFuture} that completes when the teleport is finished
*/ */
public CompletableFuture<TeleportResult> execute() { public CompletableFuture<CompletedTeleport> execute() {
// Validate the teleporter // Validate the teleporter
if (teleporter == null) { if (teleporter == null) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_TELEPORTER_NOT_RESOLVED) return CompletableFuture.completedFuture(TeleportResult.FAILED_TELEPORTER_NOT_RESOLVED)
.thenApply(resultState -> TeleportResult.from(resultState, this)); .thenApply(resultState -> CompletedTeleport.from(resultState, this));
} }
// Validate the target // Validate the target
if (target == null) { if (target == null) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_TARGET_NOT_RESOLVED) return CompletableFuture.completedFuture(TeleportResult.FAILED_TARGET_NOT_RESOLVED)
.thenApply(resultState -> TeleportResult.from(resultState, this)); .thenApply(resultState -> CompletedTeleport.from(resultState, this));
} }
// Check economy actions // Check economy actions
for (Settings.EconomyAction economyAction : economyActions) { for (Settings.EconomyAction economyAction : economyActions) {
if (!plugin.validateEconomyCheck(executor, economyAction)) { if (!plugin.validateEconomyCheck(executor, economyAction)) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.CANCELLED_ECONOMY) return CompletableFuture.completedFuture(TeleportResult.CANCELLED_ECONOMY)
.thenApply(resultState -> TeleportResult.from(resultState, this)); .thenApply(resultState -> CompletedTeleport.from(resultState, this));
} }
} }
// Run the teleport and apply economy actions // Run the teleport and apply economy actions
return run(teleporter) return run(teleporter)
.thenApply(resultState -> TeleportResult.from(resultState, this)) .thenApply(resultState -> CompletedTeleport.from(resultState, this))
.thenApply(result -> { .thenApply(result -> {
if (teleporter instanceof OnlineUser user) { if (teleporter instanceof OnlineUser user) {
finish(user, result); finish(user, result);
@@ -130,7 +130,7 @@ public class Teleport {
* @param teleporter The {@link User} who is doing the teleporting * @param teleporter The {@link User} who is doing the teleporting
* @return A {@link CompletableFuture} that completes when the teleport is finished * @return A {@link CompletableFuture} that completes when the teleport is finished
*/ */
private CompletableFuture<TeleportResult.ResultState> run(@NotNull User teleporter) { private CompletableFuture<TeleportResult> run(@NotNull User teleporter) {
return teleporter instanceof OnlineUser onlineUser return teleporter instanceof OnlineUser onlineUser
? teleportLocalUser(onlineUser) ? teleportLocalUser(onlineUser)
: teleportNetworkedUser(); : teleportNetworkedUser();
@@ -140,9 +140,9 @@ public class Teleport {
* Finish the teleport, finalize economy transactions if successful and send message * Finish the teleport, finalize economy transactions if successful and send message
* *
* @param teleporter The {@link OnlineUser} who was teleported * @param teleporter The {@link OnlineUser} who was teleported
* @param result The {@link TeleportResult.ResultState} of the teleport * @param result The {@link TeleportResult} of the teleport
*/ */
private void finish(@NotNull OnlineUser teleporter, @NotNull TeleportResult result) { private void finish(@NotNull OnlineUser teleporter, @NotNull CompletedTeleport result) {
if (result.successful()) { if (result.successful()) {
// Complete economy transactions // Complete economy transactions
economyActions.forEach(economyAction -> plugin.performEconomyTransaction(executor, economyAction)); economyActions.forEach(economyAction -> plugin.performEconomyTransaction(executor, economyAction));
@@ -162,7 +162,7 @@ public class Teleport {
* @param teleporter The teleporter * @param teleporter The teleporter
* @return A {@link CompletableFuture} that completes when the teleport is finished * @return A {@link CompletableFuture} that completes when the teleport is finished
*/ */
private CompletableFuture<TeleportResult.ResultState> teleportLocalUser(@NotNull OnlineUser teleporter) { private CompletableFuture<TeleportResult> teleportLocalUser(@NotNull OnlineUser teleporter) {
assert target != null; assert target != null;
// Dispatch the teleport event and update the player's last position // Dispatch the teleport event and update the player's last position
@@ -177,20 +177,20 @@ public class Teleport {
} }
// If the target position is on another server, execute a cross-server teleport // If the target position is on another server, execute a cross-server teleport
final CompletableFuture<TeleportResult.ResultState> teleportFuture = new CompletableFuture<>(); final CompletableFuture<TeleportResult> teleportFuture = new CompletableFuture<>();
plugin.getDatabase() plugin.getDatabase()
.setCurrentTeleport(teleporter, this) .setCurrentTeleport(teleporter, this)
.thenApply(ignored -> plugin .thenApply(ignored -> plugin
.getNetworkMessenger() .getNetworkMessenger()
.sendPlayer(teleporter, target.server) .sendPlayer(teleporter, target.server)
.thenApply(completed -> completed .thenApply(completed -> completed
? TeleportResult.ResultState.COMPLETED_CROSS_SERVER ? TeleportResult.COMPLETED_CROSS_SERVER
: TeleportResult.ResultState.FAILED_INVALID_SERVER)) : TeleportResult.FAILED_INVALID_SERVER))
.orTimeout(10, TimeUnit.SECONDS) .orTimeout(10, TimeUnit.SECONDS)
.exceptionally(throwable -> { .exceptionally(throwable -> {
plugin.getLoggingAdapter().log(Level.WARNING, "Cross-server teleport timed out for " + teleporter.username); plugin.getLoggingAdapter().log(Level.WARNING, "Cross-server teleport timed out for " + teleporter.username);
plugin.getDatabase().setCurrentTeleport(teleporter, null); plugin.getDatabase().setCurrentTeleport(teleporter, null);
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_INVALID_SERVER); return CompletableFuture.completedFuture(TeleportResult.FAILED_INVALID_SERVER);
}) })
.thenAccept(result -> result.thenAcceptAsync(teleportFuture::complete)); .thenAccept(result -> result.thenAcceptAsync(teleportFuture::complete));
return teleportFuture; return teleportFuture;
@@ -200,11 +200,11 @@ public class Teleport {
* Teleport a user not on this server but on the proxy network * Teleport a user not on this server but on the proxy network
* *
* @return A {@link CompletableFuture} that completes when the teleport is finished. * @return A {@link CompletableFuture} that completes when the teleport is finished.
* Successful cross-server teleports will return {@link TeleportResult.ResultState#COMPLETED_CROSS_SERVER}. * Successful cross-server teleports will return {@link TeleportResult#COMPLETED_CROSS_SERVER}.
* @implNote Cross-server teleports will return with a {@link TeleportResult.ResultState#FAILED_INVALID_SERVER} result if the * @implNote Cross-server teleports will return with a {@link TeleportResult#FAILED_INVALID_SERVER} result if the
* target server is not online, or connection timed out * target server is not online, or connection timed out
*/ */
private CompletableFuture<TeleportResult.ResultState> teleportNetworkedUser() { private CompletableFuture<TeleportResult> teleportNetworkedUser() {
assert target != null; assert target != null;
assert teleporter != null; assert teleporter != null;
@@ -221,7 +221,7 @@ public class Teleport {
.exceptionally(throwable -> null) .exceptionally(throwable -> null)
.thenApply(result -> { .thenApply(result -> {
if (result == null || result.payload.resultState == null) { if (result == null || result.payload.resultState == null) {
return TeleportResult.ResultState.FAILED_TELEPORTER_NOT_RESOLVED; return TeleportResult.FAILED_TELEPORTER_NOT_RESOLVED;
} }
return result.payload.resultState; return result.payload.resultState;
}); });
@@ -2,7 +2,6 @@ package net.william278.huskhomes.teleport;
import net.william278.huskhomes.config.Locales; import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.position.Position; import net.william278.huskhomes.position.Position;
import net.william278.huskhomes.position.World; import net.william278.huskhomes.position.World;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -10,115 +9,10 @@ import org.jetbrains.annotations.Nullable;
import java.util.Optional; import java.util.Optional;
/**
* Represents the result of executing a {@link Teleport} or {@link TimedTeleport}
*
* @since 3.1
*/
public class TeleportResult {
/**
* The state of the {@link Teleport}
*/
@NotNull
private final ResultState state;
/**
* The {@link User} who is doing the teleporting
*/
@Nullable
private final User teleporter;
/**
* The {@link Position} the teleporter should be teleported to
*/
@Nullable
private final Position destination;
/**
* <b>Internal</b> - Create a new {@link TeleportResult} (use {@link #from(ResultState, Teleport)})
*
* @param state The {@link ResultState} of completing the teleport
* @param teleporter The {@link User} who is doing the teleporting
* @param destination The {@link Position} the teleporter should be teleported to
* @since 3.1
*/
private TeleportResult(@NotNull ResultState state, @Nullable User teleporter, @Nullable Position destination) {
this.state = state;
this.teleporter = teleporter;
this.destination = destination;
}
/**
* Create a new {@link TeleportResult} for a {@link Teleport} with an outcome {@link ResultState}
*
* @param state The outcome {@link ResultState}
* @param teleport The {@link Teleport} that was executed
* @return The {@link TeleportResult} of executing the supplied {@link Teleport}
* @since 3.1
*/
public static TeleportResult from(@NotNull ResultState state, @NotNull Teleport teleport) {
return new TeleportResult(state, teleport.teleporter, teleport.target);
}
/**
* Get the state of the {@link Teleport} after execution has finished
*
* @return The {@link ResultState} of the teleport
* @since 3.1
*/
@NotNull
public ResultState getState() {
return state;
}
/**
* Returns if the teleport was successful
*
* @return {@code true} if the teleport was successful, {@code false} otherwise
* @since 3.1
*/
public boolean successful() {
return state.successful;
}
/**
* Get the {@link User} who is doing the teleporting
*
* @return The teleporter, if they were resolved
* @implNote The optional will return empty if the state is {@link ResultState#FAILED_TELEPORTER_NOT_RESOLVED}
* @since 3.1
*/
public Optional<User> getTeleporter() {
return Optional.ofNullable(teleporter);
}
/**
* Get the target {@link Position} the teleporter should have been teleported to
*
* @return The target position, if it was resolved
* @implNote The optional will return empty if the state is {@link ResultState#FAILED_TARGET_NOT_RESOLVED}
* @since 3.1
*/
public Optional<Position> getDestination() {
return Optional.ofNullable(destination);
}
/**
* Send an {@link OnlineUser} the corresponding message indicating the state of the teleport once it has executred
*
* @param locales the {@link Locales} instance to use
* @param user the {@link OnlineUser} to send the message to
* @since 3.1
*/
public void sendResultMessage(@NotNull Locales locales, @NotNull OnlineUser user) {
this.state.sendResultMessage(locales, user);
}
/** /**
* Represents the state of a {@link Teleport} after it has finished executing * Represents the state of a {@link Teleport} after it has finished executing
*/ */
public enum ResultState { public enum TeleportResult {
/** /**
* Returns if the {@link Teleport} was completed locally, successfully * Returns if the {@link Teleport} was completed locally, successfully
@@ -189,18 +83,18 @@ public class TeleportResult {
@Nullable @Nullable
private final String messageId; private final String messageId;
ResultState(boolean successful, @NotNull String messageId) { TeleportResult(boolean successful, @NotNull String messageId) {
this.successful = successful; this.successful = successful;
this.messageId = messageId; this.messageId = messageId;
} }
ResultState(boolean successful) { TeleportResult(boolean successful) {
this.successful = successful; this.successful = successful;
this.messageId = null; this.messageId = null;
} }
/** /**
* Send an {@link OnlineUser} the corresponding message for this {@link ResultState}, if there is one * Send an {@link OnlineUser} the corresponding message for this {@link TeleportResult}, if there is one
* *
* @param locales the {@link Locales} instance to use * @param locales the {@link Locales} instance to use
* @param user the {@link OnlineUser} to send the message to * @param user the {@link OnlineUser} to send the message to
@@ -211,4 +105,3 @@ public class TeleportResult {
} }
} }
}
@@ -40,17 +40,17 @@ public class TimedTeleport extends Teleport {
* @return a {@link CompletableFuture} that completes when the teleport is complete or has been cancelled * @return a {@link CompletableFuture} that completes when the teleport is complete or has been cancelled
*/ */
@Override @Override
public CompletableFuture<TeleportResult> execute() { public CompletableFuture<CompletedTeleport> execute() {
// If the target has not been resolved, fail the teleport // If the target has not been resolved, fail the teleport
if (target == null) { if (target == null) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_TARGET_NOT_RESOLVED) return CompletableFuture.completedFuture(TeleportResult.FAILED_TARGET_NOT_RESOLVED)
.thenApply(resultState -> TeleportResult.from(resultState, this)); .thenApply(resultState -> CompletedTeleport.from(resultState, this));
} }
// Check if the teleporter is already warming up to teleport // Check if the teleporter is already warming up to teleport
if (plugin.getCache().currentlyOnWarmup.contains(teleporter.uuid)) { if (plugin.getCache().currentlyOnWarmup.contains(teleporter.uuid)) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_ALREADY_TELEPORTING) return CompletableFuture.completedFuture(TeleportResult.FAILED_ALREADY_TELEPORTING)
.thenApply(resultState -> TeleportResult.from(resultState, this)); .thenApply(resultState -> CompletedTeleport.from(resultState, this));
} }
// Check if the teleporter can bypass warmup // Check if the teleporter can bypass warmup
@@ -61,21 +61,21 @@ public class TimedTeleport extends Teleport {
// Check economy actions // Check economy actions
for (Settings.EconomyAction economyAction : economyActions) { for (Settings.EconomyAction economyAction : economyActions) {
if (!plugin.validateEconomyCheck(executor, economyAction)) { if (!plugin.validateEconomyCheck(executor, economyAction)) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.CANCELLED_ECONOMY) return CompletableFuture.completedFuture(TeleportResult.CANCELLED_ECONOMY)
.thenApply(resultState -> TeleportResult.from(resultState, this)); .thenApply(resultState -> CompletedTeleport.from(resultState, this));
} }
} }
// Check if they are moving at the start of the teleport // Check if they are moving at the start of the teleport
if (teleporter.isMoving()) { if (teleporter.isMoving()) {
return CompletableFuture.completedFuture(TeleportResult.ResultState.FAILED_MOVING) return CompletableFuture.completedFuture(TeleportResult.FAILED_MOVING)
.thenApply(resultState -> TeleportResult.from(resultState, this)); .thenApply(resultState -> CompletedTeleport.from(resultState, this));
} }
// Process the warmup and execute the teleport // Process the warmup and execute the teleport
return process().thenApplyAsync(ignored -> { return process().thenApplyAsync(ignored -> {
if (cancelled) { if (cancelled) {
return TeleportResult.from(TeleportResult.ResultState.CANCELLED, this); return CompletedTeleport.from(TeleportResult.CANCELLED, this);
} }
return super.execute().join(); return super.execute().join();
}); });