User Tools

Site Tools


tutorial:commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:commands [2020/06/14 04:41] – Link to new suggestions page i509vcbtutorial:commands [2020/06/14 04:53] – Populate advanced concepts table i509vcb
Line 216: Line 216:
 Below are links to the articles about more complex concepts used in brigadier. Below are links to the articles about more complex concepts used in brigadier.
  
-^ Page                                           ^ Description                              +^ Page                                                           ^ Description                                                                     ^ 
-| [[tutorials:commands:suggestions|Suggestions]] | Suggesting argument values to the client |+| [[tutorials:commands:requirements|Requirements]]               | Only allow users to execute commands in certain scenarios.                      | 
 +| [[tutorials:commands:exceptions  |Exceptions]]                 | Fail execution of a command with a descriptive message and in certain contexts. |                                                                   
 +| [[tutorials:commands:suggestions |Suggestions]]                | Suggesting input to be sent to the client.                                      | 
 +| [[tutorials:commands:redirects_aliases|Redirects (Aliases)]]   | Allow use of aliases to execute commands.                                       | 
 +| [[tutorials:commands:redirects_chaining|Redirects (Chaining)]] | Allow commands to have repeating elements and flags.                            | 
 +| [[tutorials:commands:argument_types|Custom Argument Types]]    | Parse your own arguments and return your own types.                             |
  
-**TODO:** Sections are being moved to sub categories and will be added here as they are moved +**TODO:** Sections are being moved to sub categories and will be added to their respective articles as they are migrated.
- +
-===== Suggestions ===== +
- +
-Suggestions can be provided to the client to recommend what to input into the command.  This is used for Scoreboards and Loot Tables ingame. The game stores these in the SuggestionProviders. A few examples of Minecraft's built in suggestions providers are below +
-<code> +
-SUMMONABLE_ENTITIES +
-AVAILIBLE_SOUNDS +
-ALL_RECIPES +
-ASK_SERVER +
-</code> +
- +
-Loot tables specify their own SuggestionProvider inside ''LootCommand'' for example. +
- +
-The example below is a dynamically changing SuggestionProvider that lists several words for a StringArgumentType to demonstrate how it works: +
-<code java [enable_line_numbers="true"]> +
-public static SuggestionProvider<ServerCommandSource> suggestedStrings() { +
-    return (ctx, builder) -> getSuggestionsBuilder(builder, /*Access to a list here*/); +
-+
-     +
-private static CompletableFuture<Suggestions> getSuggestionsBuilder(SuggestionsBuilder builder, List<String> list) { +
-    String remaining = builder.getRemaining().toLowerCase(Locale.ROOT); +
-         +
-    if(list.isEmpty()) { // If the list is empty then return no suggestions +
-        return Suggestions.empty(); // No suggestions +
-    } +
-         +
-    for (String str : list) { // Iterate through the supplied list +
-        if (str.toLowerCase(Locale.ROOT).startsWith(remaining)) { +
-            builder.suggest(str); // Add every single entry to suggestions list. +
-        } +
-    } +
-    return builder.buildFuture(); // Create the CompletableFuture containing all the suggestions +
-+
-</code> +
- +
-The SuggestionProvider is a functional interface that returns a CompletableFuture containing a list of suggestions. These suggestions are sent to client as a command is typed and can be changed while server is running. The SuggestionProvider provides a CommandContext and a SuggestionBuilder to allow determination of all the suggestions. The CommandSource can also be taken into account during the suggestion creation process as it is available through the CommandContext. +
- +
-Though remember these are suggestions. The inputted command may not contain an argument you suggested so arguments are parsed without consideration for suggestions. +
- +
-To use the suggestion you would append it right after the argument you want to suggest possible arguments for. This can be any argument and the normal client side exception popups will still work. Note this cannot be applied to literals. +
- +
-<code java [enable_line_numbers="true"]> +
-argument(argumentName, word()) +
-.suggests(CompletionProviders.suggestedStrings()) +
-    .then(/*Rest of the command*/)); +
-</code>+
  
 ===== Requirements ===== ===== Requirements =====
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210