Refactor and simplify RandomTeleportEngine API and logic

This commit is contained in:
William278 committed 2022-11-23 11:56:58 +00:00
1 parent c8a0f00290
commit 6b55327e52
6 files changed
+109 -178

No files matched your search

@@ -62,7 +62,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
}
final Instant currentTime = Instant.now();
if (isExecutorTeleporting && !currentTime.isAfter(userData.get().rtpCooldown())
&& !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
&& !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);
@@ -70,7 +70,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
}
// Get a random position and teleport
plugin.getRandomTeleportEngine().getRandomPosition(onlineUser, rtpArguments).thenAccept(position -> {
plugin.getRandomTeleportEngine().getRandomPosition(onlineUser.getPosition().world, rtpArguments).thenAccept(position -> {
if (position.isEmpty()) {
plugin.getLocales().getLocale("error_rtp_randomization_timeout")
.ifPresent(onlineUser::sendMessage);
@@ -86,7 +86,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
teleportFuture.thenAccept(teleport -> teleport.execute()
.thenAccept(result -> {
if (isExecutorTeleporting &&
result.successful() && !onlineUser.hasPermission(Permission.BYPASS_RTP_COOLDOWN.node)) {
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)));
@@ -109,7 +109,7 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
}
plugin.getLoggingAdapter().log(Level.INFO, "Finding a random position for " + foundUser.get().username + "...");
plugin.getRandomTeleportEngine().getRandomPosition(foundUser.get(), ArrayUtils.subarray(args, 1, args.length)).thenAccept(position -> {
plugin.getRandomTeleportEngine().getRandomPosition(foundUser.get().getPosition().world, ArrayUtils.subarray(args, 1, args.length)).thenAccept(position -> {
if (position.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + foundUser.get().username + " to a random position; randomization timed out!");
return;