mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Prevent players starting a teleport warmup while moving
This commit is contained in:
1 parent
d6db45bc99
commit
6397d78767
5 files changed
+28
-1
No files matched your search
@@ -141,6 +141,12 @@ public class BukkitPlayer extends OnlineUser {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMoving() {
|
||||||
|
// Get the player momentum and return if they are moving
|
||||||
|
return player.getVelocity().length() >= 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a Bukkit plugin message
|
* Send a Bukkit plugin message
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -97,6 +97,13 @@ public abstract class OnlineUser extends User {
|
|||||||
*/
|
*/
|
||||||
public abstract CompletableFuture<TeleportResult> teleport(@NotNull Location location, boolean asynchronous);
|
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
|
* Get the maximum number of homes this user may set
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -247,7 +247,12 @@ public class TeleportManager {
|
|||||||
@NotNull Settings.EconomyAction... economyActions) {
|
@NotNull Settings.EconomyAction... economyActions) {
|
||||||
// Prevent players starting multiple timed teleports
|
// Prevent players starting multiple timed teleports
|
||||||
if (currentlyOnWarmup.contains(onlineUser.uuid)) {
|
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;
|
final int teleportWarmupTime = plugin.getSettings().teleportWarmupTime;
|
||||||
@@ -285,6 +290,8 @@ public class TeleportManager {
|
|||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
case FAILED_ALREADY_TELEPORTING -> plugin.getLocales().getLocale("error_already_teleporting")
|
case FAILED_ALREADY_TELEPORTING -> plugin.getLocales().getLocale("error_already_teleporting")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.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")
|
case FAILED_INVALID_WORLD -> plugin.getLocales().getLocale("error_invalid_on_arrival")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
case FAILED_ILLEGAL_COORDINATES -> plugin.getLocales().getLocale("error_illegal_target_coordinates")
|
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
|
* @return a future, returning when the teleport has finished
|
||||||
*/
|
*/
|
||||||
private CompletableFuture<TimedTeleport> processTeleportWarmup(@NotNull final TimedTeleport teleport) {
|
private CompletableFuture<TimedTeleport> processTeleportWarmup(@NotNull final TimedTeleport teleport) {
|
||||||
|
|
||||||
// Mark the player as warming up
|
// Mark the player as warming up
|
||||||
currentlyOnWarmup.add(teleport.getPlayer().uuid);
|
currentlyOnWarmup.add(teleport.getPlayer().uuid);
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ public enum TeleportResult {
|
|||||||
*/
|
*/
|
||||||
FAILED_ALREADY_TELEPORTING(false),
|
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
|
* Returns if the {@link Teleport} failed because the {@link World} of the
|
||||||
* target {@link Position} could not be found
|
* target {@link Position} could not be found
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ error_public_home_invalid: '[Error:](#ff3300) [Could not find a public home owne
|
|||||||
error_set_home_maximum_homes: '[Error:](#ff3300) [You can only set a maximum of %1% homes!](#ff7e5e)'
|
error_set_home_maximum_homes: '[Error:](#ff3300) [You can only set a maximum of %1% homes!](#ff7e5e)'
|
||||||
error_spawn_not_set: '[Error:](#ff3300) [The spawn position has not been set.](#ff7e5e)'
|
error_spawn_not_set: '[Error:](#ff3300) [The spawn position has not been set.](#ff7e5e)'
|
||||||
error_no_teleport_requests: '[Error:](#ff3300) [You do not have a pending teleport request.](#ff7e5e)'
|
error_no_teleport_requests: '[Error:](#ff3300) [You do not have a pending teleport request.](#ff7e5e)'
|
||||||
|
error_teleport_warmup_stand_still: '[Error:](#ff3300) [You must be standing still before starting a teleport!](#ff7e5e)'
|
||||||
error_teleport_request_expired: '[Error:](#ff3300) [Your pending teleport request has expired.](#ff7e5e)'
|
error_teleport_request_expired: '[Error:](#ff3300) [Your pending teleport request has expired.](#ff7e5e)'
|
||||||
error_teleport_request_sender_not_online: '[Error:](#ff3300) [The sender of your pending teleport request is no longer online.](#ff7e5e)'
|
error_teleport_request_sender_not_online: '[Error:](#ff3300) [The sender of your pending teleport request is no longer online.](#ff7e5e)'
|
||||||
error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests.](#ff7e5e) [[Stop Ignoring…]](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)'
|
error_ignoring_teleport_requests: '[Error:](#ff3300) [You are currently ignoring teleport requests.](#ff7e5e) [[Stop Ignoring…]](#ff7e5e show_text=&#ff7e5e&Click to listen for incoming teleport requests run_command=/huskhomes:tpignore)'
|
||||||
|
|||||||
Reference in new issue
Block a user