Console /rtp command

This commit is contained in:
William committed 2022-08-24 23:24:26 +01:00
1 parent 9e58fc3a32
commit f72c01d10b
2 files changed
+30 -3

No files matched your search

@@ -12,6 +12,7 @@ import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
public class RtpCommand extends CommandBase implements ConsoleExecutable {
@@ -93,6 +94,32 @@ public class RtpCommand extends CommandBase implements ConsoleExecutable {
@Override
public void onConsoleExecute(@NotNull String[] args) {
//todo
if (args.length == 0) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: rtp [player]");
return;
}
final Optional<OnlineUser> foundUser = plugin.findPlayer(args[0]);
if (foundUser.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Finding a random position for " + foundUser.get().username + "...");
plugin.getRtpEngine().getRandomPosition(foundUser.get().getPosition()).thenAccept(position -> {
if (position.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + foundUser.get().username + " to a random position; randomization timed out!");
return;
}
plugin.getTeleportManager().teleport(foundUser.get(), position.get())
.thenAccept(result -> {
if (result.successful) {
plugin.getLoggingAdapter().log(Level.INFO, "Teleported" + foundUser.get().username + " to a random position.");
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport" + foundUser.get().username + " to a random position.");
}
plugin.getTeleportManager().finishTeleport(foundUser.get(), result);
}).join();
});
}
}
@@ -129,7 +129,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
@Override
public void onConsoleExecute(@NotNull String[] args) {
if (args.length < 2 || args.length > 6) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax: /tp <player> <destination>");
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: tp <player> <destination>");
return;
}
final OnlineUser playerToTeleport = plugin.findPlayer(args[0]).orElse(null);
@@ -150,7 +150,7 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
args.length >= 5 ? new World(args[4], UUID.randomUUID()) : plugin.getWorlds().get(0),
args.length == 6 ? new Server(args[5]) : plugin.getServer(playerToTeleport)));
} catch (NumberFormatException e) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax: /tp <player> <x> <y> <z> [world] [server]");
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: tp <player> <x> <y> <z> [world] [server]");
return;
}
}