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.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<String> 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<String> suggestGamerules() {

View File

@ -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 extends CommandFlag> T flag(T flag) {
if (flagGroupBuilder == null) {
flagGroupBuilder = CommandFlagGroup.builder("mv" + getClass().getSimpleName().toLowerCase());
}
flagGroupBuilder.add(flag);
Logging.finest("Registered flag: " + flag);
return flag;
}

View File

@ -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.
*

View File

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