More work on commands

This commit is contained in:
William committed 2023-03-12 12:49:46 +00:00
1 parent 0bd63a9f01
commit a72109667a
33 files changed
+445 -382

No files matched your search

@@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public class DelHomeCommand extends SavedPositionCommand<Home> implements TabProvider {
public class DelHomeCommand extends SavedPositionCommand<Home> {
public DelHomeCommand(@NotNull HuskHomes implementor) {
super("delhome", List.of(), Home.class, List.of(), implementor);
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public class DelWarpCommand extends SavedPositionCommand<Warp> implements TabProvider {
public class DelWarpCommand extends SavedPositionCommand<Warp> {
public DelWarpCommand(@NotNull HuskHomes implementor) {
super("delwarp", List.of(), Warp.class, List.of(), implementor);
@@ -4,72 +4,130 @@ import de.themoep.minedown.adventure.MineDown;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.hook.EconomyHook;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.position.Home;
import net.william278.huskhomes.position.PositionMeta;
import net.william278.huskhomes.user.CommandUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import net.william278.huskhomes.util.ValidationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class EditHomeCommand extends Command implements TabProvider {
public class EditHomeCommand extends SavedPositionCommand<Home> {
private final String[] EDIT_HOME_COMPLETIONS = {"rename", "description", "relocate", "privacy"};
public EditHomeCommand(@NotNull HuskHomes implementor) {
super("edithome", Permission.COMMAND_EDIT_HOME, implementor);
public EditHomeCommand(@NotNull HuskHomes plugin) {
super("edithome", List.of(), Home.class, List.of("rename", "description", "relocate", "privacy"), plugin);
}
@Override
public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) {
if (args.length >= 1) {
final String homeName = args[0];
final String editOperation = args.length >= 2 ? args[1] : null;
final String editArgs = getEditArguments(args);
public void execute(@NotNull CommandUser executor, @NotNull Home home, @NotNull String[] args) {
final boolean ownerEditing = home.getOwner().equals(executor);
if (!ownerEditing && !executor.hasPermission(getOtherPermission())) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(executor::sendMessage);
return;
}
RegexUtil.matchDisambiguatedHomeIdentifier(homeName).ifPresentOrElse(
homeIdentifier -> plugin.getDatabase().getUserDataByName(homeIdentifier.ownerName())
.thenAcceptAsync(optionalUserData -> optionalUserData.ifPresentOrElse(userData -> {
if (!userData.getUserUuid().equals(onlineUser.getUuid())) {
if (!onlineUser.hasPermission(Permission.COMMAND_EDIT_HOME_OTHER.node)) {
plugin.getLocales().getLocale("error_no_permission")
.ifPresent(onlineUser::sendMessage);
return;
}
}
plugin.getDatabase().getHome(userData.user(), homeIdentifier.homeName()).thenAcceptAsync(optionalHome -> {
if (optionalHome.isEmpty()) {
plugin.getLocales().getLocale("error_home_invalid_other",
homeIdentifier.ownerName(), homeIdentifier.homeName())
.ifPresent(onlineUser::sendMessage);
return;
}
editHome(optionalHome.get(), onlineUser, editOperation, editArgs);
});
final Optional<String> operation = parseStringArg(args, 0);
if (operation.isEmpty()) {
getHomeEditorWindow(home, true, !ownerEditing,
!ownerEditing || executor.hasPermission(Permission.COMMAND_HOME_OTHER.node),
executor.hasPermission(Permission.COMMAND_EDIT_HOME_PRIVACY.node))
.forEach(executor::sendMessage);
return;
}
},
() -> plugin.getLocales().getLocale("error_home_invalid_other",
homeIdentifier.ownerName(), homeIdentifier.homeName())
.ifPresent(onlineUser::sendMessage))),
() -> plugin.getDatabase().getHome(onlineUser, homeName).thenAcceptAsync(optionalHome -> {
if (optionalHome.isEmpty()) {
plugin.getLocales().getLocale("error_home_invalid", homeName)
.ifPresent(onlineUser::sendMessage);
return;
}
editHome(optionalHome.get(), onlineUser, editOperation, editArgs);
})
);
} else {
if (!arguments.contains(operation.get().toLowerCase())) {
plugin.getLocales().getLocale("error_invalid_syntax",
"/edithome <name> [" + String.join("|", EDIT_HOME_COMPLETIONS) + "] [args]")
.ifPresent(onlineUser::sendMessage);
"/edithome " + home.getName() + " <" + String.join("|", arguments) + ">")
.ifPresent(executor::sendMessage);
return;
}
switch (operation.get().toLowerCase()) {
case "rename" -> {
final Optional<String> newName = parseStringArg(args, 1);
if (newName.isEmpty()) {
plugin.getLocales().getLocale("error_invalid_syntax",
"/edithome " + home.getName() + " rename <name>")
.ifPresent(executor::sendMessage);
return;
}
try {
plugin.getManager().homes().renameHome(home.getOwner(), home.getName(), newName.get());
} catch (ValidationException e) {
e.dispatchHomeError(executor, false, plugin, newName.get());
return;
}
if (ownerEditing) {
plugin.getLocales().getLocale("edit_home_update_name", home.getName(), newName.get())
.ifPresent(executor::sendMessage);
} else {
plugin.getLocales().getLocale("edit_home_update_name_other", home.getOwner().getUsername(),
home.getName(), newName.get())
.ifPresent(executor::sendMessage);
}
}
case "description" -> {
final Optional<String> newDescription = parseGreedyString(args, 1);
if (newDescription.isEmpty()) {
plugin.getLocales().getLocale("error_invalid_syntax",
"/edithome " + home.getName() + " description <text>")
.ifPresent(executor::sendMessage);
return;
}
try {
plugin.getManager().homes().updateHomeDescription(home.getOwner(), home.getName(), newDescription.get());
} catch (ValidationException e) {
e.dispatchHomeError(executor, false, plugin, newDescription.get());
return;
}
if (ownerEditing) {
plugin.getLocales().getLocale("edit_home_update_description", home.getName(), newDescription.get())
.ifPresent(executor::sendMessage);
} else {
plugin.getLocales().getLocale("edit_home_update_description_other", home.getOwner().getUsername(),
home.getName(), newDescription.get())
.ifPresent(executor::sendMessage);
}
}
case "relocate" -> {
if (!(executor instanceof OnlineUser user)) {
plugin.getLocales().getLocale("error_in_game_only")
.ifPresent(executor::sendMessage);
return;
}
try {
plugin.getManager().homes().relocateHome(user, home.getName(), user.getPosition());
} catch (ValidationException e) {
e.dispatchHomeError(executor, false, plugin, home.getName());
}
if (ownerEditing) {
plugin.getLocales().getLocale("edit_home_update_location", home.getName())
.ifPresent(executor::sendMessage);
} else {
plugin.getLocales().getLocale("edit_home_update_location_other", home.getOwner().getUsername(), home.getName())
.ifPresent(executor::sendMessage);
}
}
case "privacy" -> {
}
}
}
@@ -87,10 +145,6 @@ public class EditHomeCommand extends Command implements TabProvider {
final boolean otherOwner = !editor.equals(home.getOwner());
if (editOperation == null) {
getHomeEditorWindow(home, true, otherOwner,
!otherOwner || editor.hasPermission(Permission.COMMAND_HOME_OTHER.node),
editor.hasPermission(Permission.COMMAND_EDIT_HOME_PRIVACY.node))
.forEach(editor::sendMessage);
return;
}
if (editArgs != null) {
@@ -163,24 +217,23 @@ public class EditHomeCommand extends Command implements TabProvider {
default -> plugin.getLocales().getLocale("error_home_name_characters");
}).ifPresent(editor::sendMessage));
}
case "relocate" ->
plugin.getManager().updateHomePosition(home, editor.getPosition()).thenRun(() -> {
if (home.getOwner().equals(editor)) {
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location",
home.getMeta().getName()).orElse(new MineDown("")));
} else {
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location_other",
home.getOwner().getUsername(), home.getMeta().getName()).orElse(new MineDown("")));
}
case "relocate" -> plugin.getManager().updateHomePosition(home, editor.getPosition()).thenRun(() -> {
if (home.getOwner().equals(editor)) {
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location",
home.getMeta().getName()).orElse(new MineDown("")));
} else {
editor.sendMessage(plugin.getLocales().getLocale("edit_home_update_location_other",
home.getOwner().getUsername(), home.getMeta().getName()).orElse(new MineDown("")));
}
// Show the menu if the menu flag is set
if (showMenuFlag.get()) {
getHomeEditorWindow(home, false, otherOwner,
!otherOwner || editor.hasPermission(Permission.COMMAND_HOME_OTHER.node),
editor.hasPermission(Permission.COMMAND_EDIT_HOME_PRIVACY.node))
.forEach(editor::sendMessage);
}
});
// Show the menu if the menu flag is set
if (showMenuFlag.get()) {
getHomeEditorWindow(home, false, otherOwner,
!otherOwner || editor.hasPermission(Permission.COMMAND_HOME_OTHER.node),
editor.hasPermission(Permission.COMMAND_EDIT_HOME_PRIVACY.node))
.forEach(editor::sendMessage);
}
});
case "privacy" -> {
if (!editor.hasPermission(Permission.COMMAND_EDIT_HOME_PRIVACY.node)) {
plugin.getLocales().getLocale("error_no_permission")
@@ -344,23 +397,4 @@ public class EditHomeCommand extends Command implements TabProvider {
}};
}
@Override
@NotNull
public final List<String> suggest(@NotNull CommandUser user, @NotNull String[] args) {
if (user == null) {
return Collections.emptyList();
}
return switch (args.length) {
case 0, 1 -> plugin.getCache().getHomes().getOrDefault(user.getUuid(), new ArrayList<>())
.stream()
.filter(s -> s.toLowerCase().startsWith(args.length == 1 ? args[0].toLowerCase() : ""))
.sorted()
.collect(Collectors.toList());
case 2 -> Arrays.stream(EDIT_HOME_COMPLETIONS)
.filter(s -> s.toLowerCase().startsWith(args[1].toLowerCase()))
.sorted()
.collect(Collectors.toList());
default -> Collections.emptyList();
};
}
}
@@ -85,13 +85,13 @@ public class HomeCommand extends Command implements TabProvider, ConsoleExecutab
@Override
public void onConsoleExecute(@NotNull String[] args) {
if (args.length != 2) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: home <player> <home>");
plugin.log(Level.WARNING, "Invalid syntax. Usage: home <player> <home>");
return;
}
CompletableFuture.runAsync(() -> {
final OnlineUser playerToTeleport = plugin.findOnlinePlayer(args[0]).orElse(null);
if (playerToTeleport == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
plugin.log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final AtomicReference<Home> matchedHome = new AtomicReference<>(null);
@@ -105,11 +105,11 @@ public class HomeCommand extends Command implements TabProvider, ConsoleExecutab
final Home home = matchedHome.get();
if (home == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Could not find home '" + args[1] + "'");
plugin.log(Level.WARNING, "Could not find home '" + args[1] + "'");
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to "
plugin.log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to "
+ home.getOwner().getUsername() + "." + home.getMeta().getName());
Teleport.builder(plugin, playerToTeleport)
.setTarget(home)
@@ -86,29 +86,29 @@ public class HomeListCommand extends Command implements ConsoleExecutable {
@Override
public void onConsoleExecute(@NotNull String[] args) {
if (args.length != 1) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: homelist <player>");
plugin.log(Level.WARNING, "Invalid syntax. Usage: homelist <player>");
return;
}
CompletableFuture.runAsync(() -> {
final Optional<SavedUser> userData = plugin.getDatabase().getUserDataByName(args[0]).join();
if (userData.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
plugin.log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final List<Home> homes = plugin.getDatabase().getHomes(userData.get().user()).join();
StringJoiner rowJoiner = new StringJoiner("\t");
plugin.getLoggingAdapter().log(Level.INFO, "List of " + userData.get().user().getUsername() + "'s "
plugin.log(Level.INFO, "List of " + userData.get().user().getUsername() + "'s "
+ homes.size() + " homes:");
for (int i = 0; i < homes.size(); i++) {
final String home = homes.get(i).getMeta().getName();
rowJoiner.add(home.length() < 16 ? home + " ".repeat(16 - home.length()) : home);
if ((i + 1) % 3 == 0) {
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
plugin.log(Level.INFO, rowJoiner.toString());
rowJoiner = new StringJoiner("\t");
}
}
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
plugin.log(Level.INFO, rowJoiner.toString());
});
}
}
@@ -116,33 +116,33 @@ public class HuskHomesCommand extends Command implements ConsoleExecutable, TabP
public void onConsoleExecute(@NotNull String[] args) {
if (args.length == 0) {
Arrays.stream(aboutMenu.toString().split("\n")).forEach(message ->
plugin.getLoggingAdapter().log(Level.INFO, message));
plugin.log(Level.INFO, message));
return;
}
switch (args[0].toLowerCase()) {
case "about" -> Arrays.stream(aboutMenu.toString().split("\n")).forEach(message ->
plugin.getLoggingAdapter().log(Level.INFO, message));
plugin.log(Level.INFO, message));
case "help" -> {
plugin.getLoggingAdapter().log(Level.INFO, "List of enabled console-executable commands:");
plugin.log(Level.INFO, "List of enabled console-executable commands:");
plugin.getCommands()
.stream().filter(command -> command instanceof ConsoleExecutable)
.forEach(command -> plugin.getLoggingAdapter().log(Level.INFO,
.forEach(command -> plugin.log(Level.INFO,
command.command +
(command.command.length() < 16 ? " ".repeat(16 - command.command.length()) : "")
+ " - " + command.getDescription()));
}
case "reload" -> {
if (!plugin.reload()) {
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to reload the plugin.");
plugin.log(Level.SEVERE, "Failed to reload the plugin.");
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Reloaded config & message files.");
plugin.log(Level.INFO, "Reloaded config & message files.");
}
case "update" -> plugin.getLatestVersionIfOutdated().thenAccept(newestVersion ->
newestVersion.ifPresentOrElse(newVersion -> plugin.getLoggingAdapter().log(Level.WARNING,
newestVersion.ifPresentOrElse(newVersion -> plugin.log(Level.WARNING,
"An update is available for HuskHomes, v" + newVersion
+ " (Running v" + plugin.getVersion() + ")"),
() -> plugin.getLoggingAdapter().log(Level.INFO,
() -> plugin.log(Level.INFO,
"HuskHomes is up to date" +
" (Running v" + plugin.getVersion() + ")")));
}
@@ -97,13 +97,13 @@ public class PublicHomeCommand extends Command implements TabProvider, ConsoleEx
@Override
public void onConsoleExecute(@NotNull String[] args) {
if (args.length != 2) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: publichome <player> <[owner_name].[home_name]>");
plugin.log(Level.WARNING, "Invalid syntax. Usage: publichome <player> <[owner_name].[home_name]>");
return;
}
CompletableFuture.runAsync(() -> {
final OnlineUser playerToTeleport = plugin.findOnlinePlayer(args[0]).orElse(null);
if (playerToTeleport == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
plugin.log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final AtomicReference<Home> matchedHome = new AtomicReference<>(null);
@@ -119,11 +119,11 @@ public class PublicHomeCommand extends Command implements TabProvider, ConsoleEx
final Home home = matchedHome.get();
if (home == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Could not find public home '" + args[1] + "'");
plugin.log(Level.WARNING, "Could not find public home '" + args[1] + "'");
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to "
plugin.log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to "
+ home.getOwner().getUsername() + "." + home.getMeta().getName());
Teleport.builder(plugin, playerToTeleport)
.setTarget(home)
@@ -66,7 +66,7 @@ public class PublicHomeListCommand extends Command implements ConsoleExecutable
final List<Home> homes = plugin.getDatabase().getPublicHomes().join();
StringJoiner rowJoiner = new StringJoiner("\t");
plugin.getLoggingAdapter().log(Level.INFO, "List of " + homes.size() + " public homes:");
plugin.log(Level.INFO, "List of " + homes.size() + " public homes:");
for (int i = 0; i < homes.size(); i++) {
final String ownerUsername = homes.get(i).getOwner().getUsername();
final String homeName = homes.get(i).getMeta().getName();
@@ -74,11 +74,11 @@ public class PublicHomeListCommand extends Command implements ConsoleExecutable
int spacingSize = (16 - ownerUsername.length()) + 17;
rowJoiner.add(home.length() < spacingSize ? home + " ".repeat(spacingSize - home.length()) : home);
if ((i + 1) % 3 == 0) {
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
plugin.log(Level.INFO, rowJoiner.toString());
rowJoiner = new StringJoiner("\t");
}
}
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
plugin.log(Level.INFO, rowJoiner.toString());
});
}
}
@@ -100,19 +100,19 @@ public class RtpCommand extends Command implements ConsoleExecutable {
@Override
public void onConsoleExecute(@NotNull String[] args) {
if (args.length == 0) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: rtp [player]");
plugin.log(Level.WARNING, "Invalid syntax. Usage: rtp [player]");
return;
}
final Optional<OnlineUser> foundUser = plugin.findOnlinePlayer(args[0]);
if (foundUser.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
plugin.log(Level.WARNING, "Player not found: " + args[0]);
return;
}
plugin.getLoggingAdapter().log(Level.INFO, "Finding a random position for " + foundUser.get().getUsername() + "...");
plugin.log(Level.INFO, "Finding a random position for " + foundUser.get().getUsername() + "...");
plugin.getRandomTeleportEngine().getRandomPosition(foundUser.get().getPosition().getWorld(), ArrayUtils.subarray(args, 1, args.length)).thenAccept(position -> {
if (position.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + foundUser.get().getUsername() + " to a random position; randomization timed out!");
plugin.log(Level.WARNING, "Failed to teleport " + foundUser.get().getUsername() + " to a random position; randomization timed out!");
return;
}
Teleport.builder(plugin, foundUser.get())
@@ -120,9 +120,9 @@ public class RtpCommand extends Command implements ConsoleExecutable {
.toTeleport()
.thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful()) {
plugin.getLoggingAdapter().log(Level.INFO, "Teleported " + foundUser.get().getUsername() + " to a random position.");
plugin.log(Level.INFO, "Teleported " + foundUser.get().getUsername() + " to a random position.");
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport" + foundUser.get().getUsername() + " to a random position.");
plugin.log(Level.WARNING, "Failed to teleport" + foundUser.get().getUsername() + " to a random position.");
}
}));
});
@@ -16,7 +16,7 @@ import java.util.Optional;
public abstract class SavedPositionCommand<T extends SavedPosition> extends Command {
private final Class<T> positionType;
private final List<String> arguments;
protected final List<String> arguments;
protected SavedPositionCommand(@NotNull String name, @NotNull List<String> aliases, @NotNull Class<T> positionType,
@NotNull List<String> arguments, @NotNull HuskHomes plugin) {
@@ -159,12 +159,12 @@ public class TpCommand extends Command implements TabProvider, ConsoleExecutable
@Override
public void onConsoleExecute(@NotNull String[] args) {
if (args.length < 2 || args.length > 6) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: tp <player> <destination>");
plugin.log(Level.WARNING, "Invalid syntax. Usage: tp <player> <destination>");
return;
}
final OnlineUser playerToTeleport = plugin.findOnlinePlayer(args[0]).orElse(null);
if (playerToTeleport == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
plugin.log(Level.WARNING, "Player not found: " + args[0]);
return;
}
final TeleportTarget teleportTarget;
@@ -180,7 +180,7 @@ public class TpCommand extends Command implements TabProvider, ConsoleExecutable
args.length >= 5 ? new World(args[4], UUID.randomUUID()) : plugin.getWorlds().get(0),
args.length == 6 ? new Server(args[5]) : plugin.getServerName()));
} catch (NumberFormatException e) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: tp <player> <x> <y> <z> [world] [server]");
plugin.log(Level.WARNING, "Invalid syntax. Usage: tp <player> <x> <y> <z> [world] [server]");
return;
}
}
@@ -195,9 +195,9 @@ public class TpCommand extends Command implements TabProvider, ConsoleExecutable
}
builder.toTeleport().thenAccept(teleport -> teleport.execute().thenAccept(result -> {
if (result.successful()) {
plugin.getLoggingAdapter().log(Level.INFO, "Successfully teleported " + playerToTeleport.getUsername());
plugin.log(Level.INFO, "Successfully teleported " + playerToTeleport.getUsername());
} else {
plugin.getLoggingAdapter().log(Level.WARNING, "Failed to teleport " + playerToTeleport.getUsername() + " to " + teleportTarget);
plugin.log(Level.WARNING, "Failed to teleport " + playerToTeleport.getUsername() + " to " + teleportTarget);
}
}));
}
@@ -74,23 +74,23 @@ public class WarpCommand extends Command implements TabProvider, ConsoleExecutab
@Override
public void onConsoleExecute(@NotNull String[] args) {
if (args.length != 2) {
plugin.getLoggingAdapter().log(Level.WARNING, "Invalid syntax. Usage: warp <player> <warp>");
plugin.log(Level.WARNING, "Invalid syntax. Usage: warp <player> <warp>");
return;
}
final OnlineUser playerToTeleport = plugin.findOnlinePlayer(args[0]).orElse(null);
if (playerToTeleport == null) {
plugin.getLoggingAdapter().log(Level.WARNING, "Player not found: " + args[0]);
plugin.log(Level.WARNING, "Player not found: " + args[0]);
return;
}
plugin.getDatabase().getWarp(args[1]).thenAccept(optionalWarp -> {
if (optionalWarp.isEmpty()) {
plugin.getLoggingAdapter().log(Level.WARNING, "Could not find warp '" + args[1] + "'");
plugin.log(Level.WARNING, "Could not find warp '" + args[1] + "'");
return;
}
final Warp warp = optionalWarp.get();
plugin.getLoggingAdapter().log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to " + warp.getMeta().getName());
plugin.log(Level.INFO, "Teleporting " + playerToTeleport.getUsername() + " to " + warp.getMeta().getName());
Teleport.builder(plugin, playerToTeleport)
.setTarget(warp)
.toTimedTeleport()
@@ -64,18 +64,18 @@ public class WarpListCommand extends Command implements ConsoleExecutable {
@Override
public void onConsoleExecute(@NotNull String[] args) {
plugin.getDatabase().getWarps().thenAccept(warps -> {
plugin.getLoggingAdapter().log(Level.INFO, "List of " + warps.size() + " warps:");
plugin.log(Level.INFO, "List of " + warps.size() + " warps:");
StringJoiner rowJoiner = new StringJoiner("\t");
for (int i = 0; i < warps.size(); i++) {
final String warp = warps.get(i).meta.name;
rowJoiner.add(warp.length() < 16 ? warp + " ".repeat(16 - warp.length()) : warp);
if ((i + 1) % 3 == 0) {
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
plugin.log(Level.INFO, rowJoiner.toString());
rowJoiner = new StringJoiner("\t");
}
}
plugin.getLoggingAdapter().log(Level.INFO, rowJoiner.toString());
plugin.log(Level.INFO, rowJoiner.toString());
});
}
}