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

feat: Document custom argument suggestions #536

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Strokkur424
Copy link
Contributor

Closes #527.

Extending onto the Brigadier documentation, here I have documented the suggests method of a RequiredArgumentBuilder.

Copy link

github-actions bot commented Jan 22, 2025

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
papermc-docs ✅ Ready (View Log) Visit Preview 91ce110

@Strokkur424
Copy link
Contributor Author

/mergeable

Copy link
Member

@olijeffers0n olijeffers0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The index page still says this page is a WIP though. Needs updating :)

@Strokkur424
Copy link
Contributor Author

I mean, I didn't even mention this specific page in the WIP section. But I did add it now. Anything else?


This example obviously does not suggest anything, as we haven't added any suggestions yet.

## The `SuggestionBuilder`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo SuggestionsBuilder

| getRemainingLowerCase() | asumm13text | The input for the current argument, lowercased |

### Suggestions
The following overloads of the `SuggestionBuilder#suggest` method add values that will be send to the client as argument suggestions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same typo here


// Retrieve our argument values
final ItemStack item = ctx.getArgument("item", ItemStack.class);
final int amount = IntegerArgumentType.getInteger(ctx, "stacksize");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount is better for the argument name i think


// Set the item's amount and give it to the player
item.setAmount(amount);
player.getInventory().setItem(player.getInventory().firstEmpty(), item);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be better using the new Player#give method to handle stack size properly. But if you think it's too complicated the first empty slot could be saved in a separate var.

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 this pull request may close these issues.

[Brigadier] Document custom argument suggestions
4 participants