Fix some regression on command flag registering and completion

This commit is contained in:
Ben Woo 2023-09-10 13:54:44 +08:00
parent c71bdd83d6
commit 95a1fddbe5
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
4 changed files with 21 additions and 5 deletions

View File

@ -21,6 +21,7 @@ import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.config.MVCoreConfig; import com.onarandombox.MultiverseCore.config.MVCoreConfig;
import com.onarandombox.MultiverseCore.destination.DestinationsProvider; import com.onarandombox.MultiverseCore.destination.DestinationsProvider;
import com.onarandombox.MultiverseCore.destination.ParsedDestination; import com.onarandombox.MultiverseCore.destination.ParsedDestination;
import io.vavr.control.Try;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -95,8 +96,11 @@ public class MVCommandCompletions extends PaperCommandCompletions {
} }
private Collection<String> suggestFlags(@NotNull BukkitCommandCompletionContext context) { private Collection<String> suggestFlags(@NotNull BukkitCommandCompletionContext context) {
return this.commandManager.getFlagsManager().suggest( String groupName = context.getConfig("groupName", "");
context.getConfig("groupName", ""), context.getContextValue(String[].class));
return Try.of(() -> context.getContextValue(String[].class))
.map(flags -> commandManager.getFlagsManager().suggest(groupName, flags))
.getOrElse(Collections.emptyList());
} }
private Collection<String> suggestGamerules() { private Collection<String> suggestGamerules() {

View File

@ -33,11 +33,12 @@ public abstract class MultiverseCommand extends BaseCommand {
return commandManager.getFlagsManager(); return commandManager.getFlagsManager();
} }
protected CommandFlag flag(CommandFlag flag) { protected <T extends CommandFlag> T flag(T flag) {
if (flagGroupBuilder == null) { if (flagGroupBuilder == null) {
flagGroupBuilder = CommandFlagGroup.builder("mv" + getClass().getSimpleName().toLowerCase()); flagGroupBuilder = CommandFlagGroup.builder("mv" + getClass().getSimpleName().toLowerCase());
} }
flagGroupBuilder.add(flag); flagGroupBuilder.add(flag);
Logging.finest("Registered flag: " + flag);
return flag; return flag;
} }

View File

@ -52,6 +52,17 @@ public class CommandFlag {
return aliases; return aliases;
} }
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return "Builder{"
+ "key='" + key + '\''
+ ", aliases=" + aliases
+ '}';
}
/** /**
* A builder for a flag. * A builder for a flag.
* *

View File

@ -191,7 +191,7 @@ public class CommandValueFlag<T> extends CommandFlag {
* @return The flag. * @return The flag.
*/ */
@Override @Override
public @NotNull CommandFlag build() { public @NotNull CommandValueFlag<T> build() {
if (context == null && !String.class.equals(type)) { if (context == null && !String.class.equals(type)) {
throw new IllegalStateException("Context is required for none-string value flags"); throw new IllegalStateException("Context is required for none-string value flags");
} }