Fix timed teleport being used in some cases where it shouldn't

This commit is contained in:
William committed 2022-08-25 17:14:49 +01:00
1 parent 327c798f6e
commit f77d9adf27
6 files changed
+37 -30

No files matched your search

@@ -54,6 +54,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
}
final OnlineUser userToTeleport = target;
final boolean isExecutorTeleporting = userToTeleport.uuid.equals(onlineUser.uuid);
CompletableFuture.runAsync(() -> {
// Check the user is not still on /rtp cooldown
final Optional<UserData> userData = plugin.getDatabase().getUserData(onlineUser.uuid).join();
@@ -61,8 +62,9 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
return;
}
final Instant currentTime = Instant.now();
if (!userToTeleport.uuid.equals(onlineUser.uuid) &&
!currentTime.isAfter(userData.get().rtpCooldown()) && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
if (!isExecutorTeleporting
&& !currentTime.isAfter(userData.get().rtpCooldown())
&& !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
plugin.getLocales().getLocale("error_rtp_cooldown",
Long.toString(currentTime.until(userData.get().rtpCooldown(), ChronoUnit.MINUTES)))
.ifPresent(onlineUser::sendMessage);
@@ -77,17 +79,17 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
.ifPresent(onlineUser::sendMessage);
return;
}
plugin.getTeleportManager().timedTeleport(userToTeleport, position.get(), Settings.EconomyAction.RANDOM_TELEPORT)
.thenAccept(result -> {
if (userToTeleport.uuid.equals(onlineUser.uuid) &&
result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
plugin.getDatabase().updateUserData(new UserData(onlineUser,
userData.get().homeSlots(), userData.get().ignoringTeleports(),
Instant.now().plus(plugin.getSettings().rtpCooldownLength, ChronoUnit.MINUTES)));
}
plugin.getTeleportManager()
.finishTeleport(userToTeleport, result, Settings.EconomyAction.RANDOM_TELEPORT);
}).join();
(isExecutorTeleporting ? plugin.getTeleportManager().timedTeleport(userToTeleport, position.get(), Settings.EconomyAction.RANDOM_TELEPORT)
: plugin.getTeleportManager().teleport(userToTeleport, position.get())).thenAccept(result -> {
if (isExecutorTeleporting &&
result.successful && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
plugin.getDatabase().updateUserData(new UserData(onlineUser,
userData.get().homeSlots(), userData.get().ignoringTeleports(),
Instant.now().plus(plugin.getSettings().rtpCooldownLength, ChronoUnit.MINUTES)));
}
plugin.getTeleportManager().finishTeleport(userToTeleport, result,
Settings.EconomyAction.RANDOM_TELEPORT);
}).join();
}).join();
});
}
@@ -38,7 +38,7 @@ public class TpAllCommand extends CommandBase {
// Teleport every player
players.forEach(playerName -> plugin.getTeleportManager()
.teleportPlayerByName(playerName, onlineUser.getPosition(), onlineUser));
.teleportPlayerByName(playerName, onlineUser.getPosition(), onlineUser, false));
}
@@ -73,7 +73,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
// Teleport players by usernames
assert targetPosition.targetPlayer != null;
plugin.getTeleportManager()
.teleportPlayerToPlayerByName(playerToTeleportName, targetPosition.targetPlayer, onlineUser)
.teleportPlayerToPlayerByName(playerToTeleportName, targetPosition.targetPlayer, onlineUser, false)
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
result -> {
if (result.successful) {
@@ -90,7 +90,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
} else if (targetPosition.targetType == TeleportCommandTarget.TargetType.POSITION) {
// Teleport players by specified position
assert targetPosition.targetPosition != null;
plugin.getTeleportManager().teleportPlayerByName(playerToTeleportName, targetPosition.targetPosition, onlineUser)
plugin.getTeleportManager().teleportPlayerByName(playerToTeleportName, targetPosition.targetPosition, onlineUser, false)
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
result -> {
if (result.successful && !playerToTeleportName.equalsIgnoreCase(onlineUser.username)) {
@@ -160,7 +160,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
assert teleportCommandTarget.targetPlayer != null;
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.username
+ " to " + teleportCommandTarget.targetPlayer);
plugin.getTeleportManager().teleportToPlayerByName(playerToTeleport, teleportCommandTarget.targetPlayer);
plugin.getTeleportManager().teleportToPlayerByName(playerToTeleport, teleportCommandTarget.targetPlayer, false);
} else {
assert teleportCommandTarget.targetPosition != null;
plugin.getTeleportManager().teleport(playerToTeleport, teleportCommandTarget.targetPosition)
@@ -24,7 +24,7 @@ public class TpHereCommand extends CommandBase implements TabCompletable {
return;
}
final String targetPlayerName = args[0];
plugin.getTeleportManager().teleportPlayerByName(targetPlayerName, onlineUser.getPosition(), onlineUser)
plugin.getTeleportManager().teleportPlayerByName(targetPlayerName, onlineUser.getPosition(), onlineUser, false)
.thenAccept(resultIfPlayerExists -> resultIfPlayerExists.ifPresentOrElse(
result -> {
if (result.successful) {