diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java index c7836dd3..841d9a6c 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java @@ -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 "); + return; + } + CompletableFuture.runAsync(() -> { + final Optional userData = plugin.getDatabase().getUserDataByName(args[0]).join(); + if (userData.isEmpty()) { + plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]); + return; + } + final List 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()); + }); } } diff --git a/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java b/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java index 4066e357..a2ca5bbf 100644 --- a/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/PublicHomeListCommand.java @@ -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 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()); + }); } } diff --git a/common/src/main/java/net/william278/huskhomes/command/WarpListCommand.java b/common/src/main/java/net/william278/huskhomes/command/WarpListCommand.java index 0ef24700..07121eea 100644 --- a/common/src/main/java/net/william278/huskhomes/command/WarpListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/WarpListCommand.java @@ -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 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()); + }); } }