Rollczi/LiteCommands

List Argument Suggestions only provide suggestion for first Argument

Closed this issue · 2 comments

As is stated on the title, when you create a suggestion for the List type, it only provides a suggestion for the first args of the type, everything else gets no suggestion. It could be an implementation issue, but I'm not entirely sure. Below is the implementation code I have created.

Code:

public class SettingParameter extends ArgumentResolver<CommandSender, List> {
  @Override
  protected ParseResult<List> parse(Invocation<CommandSender> invocation, Argument<List> context, String argument) {
    return ParseResult.success(Collections.singletonList(argument));
  }

  @Override
  public SuggestionResult suggest(Invocation<CommandSender> invocation, Argument<List> argument, SuggestionContext context) {

    if(argument.getKeyName().equalsIgnoreCase("world-setting")) {
      return SuggestionResult.of(PhantomWorlds.createTabs);
    }
    return SuggestionResult.of(new ArrayList<>());
  }
}

//command method parameters.
public void create(@Context CommandSender commandSender, @Arg("world name") final String name, @Arg("environment")World.Environment environment, @OptionalArg("world-setting") List<String> settings) 

images:

First param:

first param

Second Param:

second param

You can create an argument resolver for string SettingParameter extends ArgumentResolver<CommandSender, String> and suggest that what do you want.

Then register it with the custom key:
.argument(String.class, ArgumentKey.of("world-setting"), new SettingParameter<>(suggester))

and use it in your code:
@Arg("world-setting") List<String> settings

But if you want to suggest only the first argument, maybe it is better to create argument resolver for one argument with your custom type e.g. SettingOption?