From 95a1fddbe5891879fe78a67296613283ae24a281 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sun, 10 Sep 2023 13:54:44 +0800 Subject: [PATCH] Fix some regression on command flag registering and completion --- .../commandtools/MVCommandCompletions.java | 8 ++++++-- .../commandtools/MultiverseCommand.java | 5 +++-- .../commandtools/flags/CommandFlag.java | 11 +++++++++++ .../commandtools/flags/CommandValueFlag.java | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java index 75d8d1dd..e1e42bc6 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java @@ -21,6 +21,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.config.MVCoreConfig; import com.onarandombox.MultiverseCore.destination.DestinationsProvider; import com.onarandombox.MultiverseCore.destination.ParsedDestination; +import io.vavr.control.Try; import jakarta.inject.Inject; import org.bukkit.GameRule; import org.jetbrains.annotations.NotNull; @@ -95,8 +96,11 @@ public class MVCommandCompletions extends PaperCommandCompletions { } private Collection suggestFlags(@NotNull BukkitCommandCompletionContext context) { - return this.commandManager.getFlagsManager().suggest( - context.getConfig("groupName", ""), context.getContextValue(String[].class)); + String groupName = context.getConfig("groupName", ""); + + return Try.of(() -> context.getContextValue(String[].class)) + .map(flags -> commandManager.getFlagsManager().suggest(groupName, flags)) + .getOrElse(Collections.emptyList()); } private Collection suggestGamerules() { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MultiverseCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MultiverseCommand.java index 8d8658f1..1225319f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MultiverseCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MultiverseCommand.java @@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Contract; @Contract -public abstract class MultiverseCommand extends BaseCommand { +public abstract class MultiverseCommand extends BaseCommand { protected final MVCommandManager commandManager; private String flagGroupName; @@ -33,11 +33,12 @@ public abstract class MultiverseCommand extends BaseCommand { return commandManager.getFlagsManager(); } - protected CommandFlag flag(CommandFlag flag) { + protected T flag(T flag) { if (flagGroupBuilder == null) { flagGroupBuilder = CommandFlagGroup.builder("mv" + getClass().getSimpleName().toLowerCase()); } flagGroupBuilder.add(flag); + Logging.finest("Registered flag: " + flag); return flag; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java index 0604f028..a11582e0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java @@ -52,6 +52,17 @@ public class CommandFlag { return aliases; } + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "Builder{" + + "key='" + key + '\'' + + ", aliases=" + aliases + + '}'; + } + /** * A builder for a flag. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java index 558250ee..3c23b450 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java @@ -191,7 +191,7 @@ public class CommandValueFlag extends CommandFlag { * @return The flag. */ @Override - public @NotNull CommandFlag build() { + public @NotNull CommandValueFlag build() { if (context == null && !String.class.equals(type)) { throw new IllegalStateException("Context is required for none-string value flags"); }