Prevent players starting a teleport warmup while moving

This commit is contained in:
William committed 2022-08-25 12:51:11 +01:00
1 parent d6db45bc99
commit 6397d78767
5 files changed
+28 -1

No files matched your search

@@ -97,6 +97,13 @@ public abstract class OnlineUser extends User {
*/
public abstract CompletableFuture<TeleportResult> teleport(@NotNull Location location, boolean asynchronous);
/**
* Returns if a player is moving (i.e. they have momentum)
*
* @return {@code true} if the player is moving; {@code false} otherwise
*/
public abstract boolean isMoving();
/**
* Get the maximum number of homes this user may set
*
@@ -247,7 +247,12 @@ public class TeleportManager {
@NotNull Settings.EconomyAction... economyActions) {
// Prevent players starting multiple timed teleports
if (currentlyOnWarmup.contains(onlineUser.uuid)) {
return CompletableFuture.supplyAsync(() -> TeleportResult.FAILED_ALREADY_TELEPORTING);
return CompletableFuture.completedFuture(TeleportResult.FAILED_ALREADY_TELEPORTING);
}
// Cancel if the player is already moving
if (onlineUser.isMoving()) {
return CompletableFuture.completedFuture(TeleportResult.FAILED_MOVING);
}
final int teleportWarmupTime = plugin.getSettings().teleportWarmupTime;
@@ -285,6 +290,8 @@ public class TeleportManager {
.ifPresent(onlineUser::sendMessage);
case FAILED_ALREADY_TELEPORTING -> plugin.getLocales().getLocale("error_already_teleporting")
.ifPresent(onlineUser::sendMessage);
case FAILED_MOVING -> plugin.getLocales().getLocale("error_teleport_warmup_stand_still")
.ifPresent(onlineUser::sendMessage);
case FAILED_INVALID_WORLD -> plugin.getLocales().getLocale("error_invalid_on_arrival")
.ifPresent(onlineUser::sendMessage);
case FAILED_ILLEGAL_COORDINATES -> plugin.getLocales().getLocale("error_illegal_target_coordinates")
@@ -370,6 +377,7 @@ public class TeleportManager {
* @return a future, returning when the teleport has finished
*/
private CompletableFuture<TimedTeleport> processTeleportWarmup(@NotNull final TimedTeleport teleport) {
// Mark the player as warming up
currentlyOnWarmup.add(teleport.getPlayer().uuid);
@@ -23,6 +23,11 @@ public enum TeleportResult {
*/
FAILED_ALREADY_TELEPORTING(false),
/**
* Returns if the {@link Teleport} warmup could not be started because they were moving
*/
FAILED_MOVING(false),
/**
* Returns if the {@link Teleport} failed because the {@link World} of the
* target {@link Position} could not be found