fix action add completion

This commit is contained in:
Pyrbu 2023-06-13 23:58:10 +02:00
parent 0acda842d6
commit 5651b39328

@ -25,7 +25,7 @@ public class ActionAddCommand implements CommandHandler {
@Override @Override
public void run(CommandContext context) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
List<InteractionCommandHandler> commands = actionRegistry.getCommands(); List<InteractionCommandHandler> commands = actionRegistry.getCommands();
context.setUsage(context.getLabel() + " action add <action type> ..."); context.setUsage(context.getLabel() + " action add <action type>");
String sub = context.popString(); String sub = context.popString();
for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) { for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) {
context.setUsage(context.getLabel() + " action add"); context.setUsage(context.getLabel() + " action add");
@ -38,12 +38,14 @@ public class ActionAddCommand implements CommandHandler {
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) return context.suggestCollection(npcRegistry.getModifiableIds());
List<InteractionCommandHandler> commands = actionRegistry.getCommands(); List<InteractionCommandHandler> commands = actionRegistry.getCommands();
if (context.argSize() == 2) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName)); if (context.argSize() == 1) return context.suggestStream(commands.stream().map(InteractionCommandHandler::getSubcommandName));
context.popString(); if (context.argSize() == 2) return context.suggestCollection(npcRegistry.getModifiableIds());
if (context.argSize() >= 3) {
String sub = context.popString(); String sub = context.popString();
context.popString();
for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) return command.suggest(context); for (InteractionCommandHandler command : commands) if (command.getSubcommandName().equalsIgnoreCase(sub)) return command.suggest(context);
}
return Collections.emptyList(); return Collections.emptyList();
} }
} }