Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Brigadier] Document custom argument suggestions #527

Open
Strokkur424 opened this issue Jan 22, 2025 · 0 comments · May be fixed by #536
Open

[Brigadier] Document custom argument suggestions #527

Strokkur424 opened this issue Jan 22, 2025 · 0 comments · May be fixed by #536

Comments

@Strokkur424
Copy link
Contributor

Note

This issue is part of a series of issues regarding the extension of the Paper documentation regarding Paper's Brigadier API.

It would be great to document the RequiredArgumentBuilder#suggests(SuggestionProvider) method in order to provide a way for developers to suggest possible input without the need of creating an entire custom argument.

For this, it would be good to examine the SuggestionProvider<S> interface and explain its usage.

An example should also be added. A possible example could be an String argument that suggests values out of a List<String>. It would also be noteworthy to mention good practices, such as filtering by current user input.

A code example should also be given. E.g:

final List<String> suggestions = List.of("first_element", "another_element", "weee");
Commands.literal("customsuggestions")
    .then(Commands.argument("input", StringArgumentType.word())
        .suggests((ctx, builder) -> {
            suggestions.forEach(element -> {
                if (element.startsWith(builder.getRemainingLowerCase())) {
                    builder.suggest(element);
                }
            });

            return builder.buildFuture();
        })
        .executes(ctx -> {
            ctx.getSource().getSender().sendRichMessage("<gold>You selected <input>!",
                Placeholder.unparsed("input", StringArgumentType.getString(ctx, "input"))
            );
            return Command.SINGLE_SUCCESS;
        })
    ).build();

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant