mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-09 17:57:36 +01:00
Fix some regression on command flag registering and completion
This commit is contained in:
parent
c71bdd83d6
commit
95a1fddbe5
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user