-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add CommandArgument #335
Merged
Merged
Add CommandArgument #335
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JorelAli
reviewed
Sep 4, 2022
commandapi-core/src/main/java/dev/jorel/commandapi/arguments/CommandAPIArgumentType.java
Outdated
Show resolved
Hide resolved
JorelAli
reviewed
Sep 4, 2022
commandapi-core/src/main/java/dev/jorel/commandapi/arguments/CommandResult.java
Show resolved
Hide resolved
JorelAli
reviewed
Sep 4, 2022
commandapi-core/src/main/java/dev/jorel/commandapi/arguments/CommandArgument.java
Show resolved
Hide resolved
Multiple paths for command suggestions are now possible with this syntax (taken from ArgumentTests): new CommandArgument("command")
.branchSuggestions(
SuggestionsBranch.suggest(
ArgumentSuggestions.strings("give"),
ArgumentSuggestions.strings(info -> Bukkit.getOnlinePlayers().stream().map(Player::getName).toArray(String[]::new))
).branch(
SuggestionsBranch.suggest(
ArgumentSuggestions.strings("diamond", "minecraft:diamond"),
ArgumentSuggestions.empty()
),
SuggestionsBranch.suggest(
ArgumentSuggestions.strings("dirt", "minecraft:dirt"),
null,
ArgumentSuggestions.empty()
)
),
SuggestionsBranch.suggest(
ArgumentSuggestions.strings("tp"),
ArgumentSuggestions.strings(info -> Bukkit.getOnlinePlayers().stream().map(Player::getName).toArray(String[]::new)),
ArgumentSuggestions.strings(info -> Bukkit.getOnlinePlayers().stream().map(Player::getName).toArray(String[]::new))
)
)
|
…mon logic into enforceReplacements
…he SuggestionsBranch class
…onsBranch#enforceReplacements
JorelAli
force-pushed
the
dev/CommandArgument
branch
from
November 2, 2022 11:51
339fa0e
to
0faac6c
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.