Add console commands for /homelist /publichomelist and /warplist

This commit is contained in:
William committed 2022-08-24 22:42:43 +01:00
1 parent d368befabd
commit 7e6f624ad6
3 files changed
+78 -3

No files matched your search

@@ -2,9 +2,18 @@ package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.User;
import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
public class HomeListCommand extends CommandBase implements ConsoleExecutable {
protected HomeListCommand(@NotNull HuskHomes implementor) {
@@ -75,6 +84,30 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable {
@Override
public void onConsoleExecute(@NotNull String[] args) {
//todo
if (args.length != 1) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: homelist <player>");
return;
}
CompletableFuture.runAsync(() -> {
final Optional<UserData> userData = plugin.getDatabase().getUserDataByName(args[0]).join();
if (userData.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final List<Home> homes = plugin.getDatabase().getHomes(userData.get().user()).join();
StringJoiner rowJoiner = new StringJoiner(" ");
plugin.getLoggingAdapter().log(Level.INFO, "List of " + userData.get().user().username + "'s "
+ homes.size() + " homes:");
for (int i = 1; i <= homes.size(); i++) {
final String home = homes.get(i).meta.name;
rowJoiner.add(home.length() < 16 ? " ".repeat(16 - home.length()) + home : home);
if (i % 3 == 0) {
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
rowJoiner = new StringJoiner(" ");
}
}
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
});
}
}
@@ -2,9 +2,17 @@ package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.player.UserData;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
public class PublicHomeListCommand extends CommandBase implements ConsoleExecutable {
protected PublicHomeListCommand(@NotNull HuskHomes implementor) {
@@ -54,6 +62,20 @@ public class PublicHomeListCommand extends CommandBase implements ConsoleExecuta
@Override
public void onConsoleExecute(@NotNull String[] args) {
//todo
CompletableFuture.runAsync(() -> {
final List<Home> homes = plugin.getDatabase().getPublicHomes().join();
StringJoiner rowJoiner = new StringJoiner(" ");
plugin.getLoggingAdapter().log(Level.INFO, "List of " + homes.size() + " public homes:");
for (int i = 1; i <= homes.size(); i++) {
final String home = homes.get(i).owner.username + homes.get(i).meta.name;
rowJoiner.add(home.length() < 33 ? " ".repeat(33 - home.length()) + home : home);
if (i % 3 == 0) {
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
rowJoiner = new StringJoiner(" ");
}
}
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
});
}
}
@@ -2,9 +2,15 @@ package net.william278.huskhomes.command;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.player.OnlineUser;
import net.william278.huskhomes.position.Warp;
import net.william278.huskhomes.util.Permission;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.StringJoiner;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
public class WarpListCommand extends CommandBase implements ConsoleExecutable {
protected WarpListCommand(@NotNull HuskHomes implementor) {
@@ -53,6 +59,20 @@ public class WarpListCommand extends CommandBase implements ConsoleExecutable {
@Override
public void onConsoleExecute(@NotNull String[] args) {
//todo
CompletableFuture.runAsync(() -> {
final List<Warp> warps = plugin.getDatabase().getWarps().join();
StringJoiner rowJoiner = new StringJoiner(" ");
plugin.getLoggingAdapter().log(Level.INFO, "List of " + warps.size() + " warps:");
for (int i = 1; i <= warps.size(); i++) {
final String warp = warps.get(i).meta.name;
rowJoiner.add(warp.length() < 16 ? " ".repeat(16 - warp.length()) + warp : warp);
if (i % 3 == 0) {
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
rowJoiner = new StringJoiner(" ");
}
}
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
});
}
}