tutorial:commands
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:commands [2020/06/14 04:41] – Link to new suggestions page i509vcb | tutorial:commands [2020/06/14 05:13] – Refactor FAQ section i509vcb | ||
---|---|---|---|
Line 212: | Line 212: | ||
CommandManager is in '' | CommandManager is in '' | ||
- | ===== Advanced concepts ===== | + | ====== Advanced concepts |
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 | + | ^ Page |
- | | [[tutorials: | + | | [[tutorials: |
+ | | [[tutorials: | ||
+ | | [[tutorials: | ||
+ | | [[tutorials: | ||
+ | | [[tutorials: | ||
+ | | [[tutorials: | ||
- | **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 |
- | ===== Suggestions | + | ====== Sorry for the mess ====== |
- | Suggestions can be provided to the client to recommend what to input into the command. | + | __Currently this article |
- | < | + | |
- | SUMMONABLE_ENTITIES | + | |
- | AVAILIBLE_SOUNDS | + | |
- | ALL_RECIPES | + | |
- | ASK_SERVER | + | |
- | </ | + | |
- | + | ||
- | Loot tables specify their own SuggestionProvider inside '' | + | |
- | + | ||
- | 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=" | + | |
- | public static SuggestionProvider< | + | |
- | return (ctx, builder) -> getSuggestionsBuilder(builder, | + | |
- | } | + | |
- | + | ||
- | private static CompletableFuture< | + | |
- | String remaining = builder.getRemaining().toLowerCase(Locale.ROOT); | + | |
- | + | ||
- | if(list.isEmpty()) { // If the list is empty then return no suggestions | + | |
- | return Suggestions.empty(); | + | |
- | } | + | |
- | + | ||
- | for (String str : list) { // Iterate through | + | |
- | if (str.toLowerCase(Locale.ROOT).startsWith(remaining)) { | + | |
- | builder.suggest(str); | + | |
- | } | + | |
- | } | + | |
- | return builder.buildFuture(); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | The SuggestionProvider is a functional interface | + | |
- | + | ||
- | 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=" | + | |
- | argument(argumentName, | + | |
- | .suggests(CompletionProviders.suggestedStrings()) | + | |
- | .then(/ | + | |
- | </ | + | |
===== Requirements ===== | ===== Requirements ===== | ||
Line 632: | Line 595: | ||
} | } | ||
</ | </ | ||
- | ===== FAQ ===== | + | ====== FAQ ====== |
+ | |||
+ | ===== Why does my command not compile ===== | ||
+ | |||
+ | There are two immediate possibilities for why this could occur. | ||
+ | |||
+ | ==== Catch or throw a CommandSyntaxException | ||
- | === What else can I send feedback | + | The solution |
- | You use the Text classes (LiteralText, | + | ==== Issues with generics ==== |
- | === Why does my IDE complain saying that a method executed by my command needs to catch or throw a CommandSyntaxException === | + | You may have an issue with generic types once in a while. Verify you are using '' |
- | The solution to this is just to make the methods throw a CommandSyntaxException. This is because brigadier handles the exceptions. | + | ===== Can I register client side commands? ===== |
- | === Can I register | + | Fabric doesn' |
- | You can do this but it is not reccomended. You would get the instance of the CommandManager and add anything you wish to the CommandDispatcher within it. | + | ===== Dark Arts ===== |
- | After that you will need to send the command tree to every player again using '' | + | A few things we don't recommend, but are possible. |
- | === Can I unregister | + | ==== Can I register |
- | You can also do this but it is very unstable and could cause unwanted side effects. Lets just say it involves a bunch of Reflection. | + | You can do this but it is not recommended. You would get the '' |
- | Once again you will need to send the command tree to every player again using '' | + | After that you need to send the command tree to every player again using '' |
- | === Can I register client side commands? === | + | ==== Can I unregister |
- | Well Fabric currently doesn' | + | You can also do this, however it is much less stable than registering commands and could cause unwanted side effects. To keep things simple, you need to use reflection on brigadier and remove |
- | https:// | + |
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210