Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #307
This PR adds the CommandArgument, based on this example for Brigadier Suggestions in the documentation. Improving upon that example, this CommandArgument uses the server's CommandMap to provide tab-completions for all commands registered on the server, plugin and Brigadier alike.
The object returned by the CommandArgument is CommandResult. This is just a simple record that bundles the Command and the arguments together, like so:
CommandResult#execute
makes it easier for developers to use the CommandResult without picking apart the record if they don't need to be that specific.The usual
replaceSuggestions(ArgumentSuggestions)
method was upgraded toreplaceSuggestions(ArgumentSuggesstions...)
for the CommandArgument. This allows developers to override each argument in the command with their own suggestions, like so:The CommandArgument of
/restrictedcommand
will only allow commands of the formgive [online player] (diamond/minecraft:diamond)
. If a user tries to enter any other command the next suggestions will stop showing up and when the command is executed an appropriate CommandSyntaxException will be thrown. Developers can also pass innull
instead of an ArgumentSuggestions to use the regular tab completions provided by the server.In order to make an ArgumentTest for the CommandArgument,
NMS#getSimpleCommandMap
was implemented in MockNMS. I also added the methodpublic <T> void assertStoresResult(CommandSender sender, String command, Mut<T> queue, T expected)
to the ArgumentTests class to reduce code redundancy when asserting the parsed result from running a command.Documentation for the CommandArgument still needs to be written. Additionally, the example for Brigadier suggestions should probably be updated. Maybe this code from discord would be a good replacement.