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/07/14 19:29] – dispatcher is not a boolean i509vcb | tutorial:commands [2020/11/25 08:07] – Move static imports up and some rewords i509vcb | ||
---|---|---|---|
Line 80: | Line 80: | ||
'' | '' | ||
To execute this command, one must type ''/ | To execute this command, one must type ''/ | ||
+ | |||
+ | ===== Static Imports ===== | ||
+ | Typing out '' | ||
+ | |||
+ | Below is an example of some static imports: | ||
+ | <code java [enable_line_numbers=" | ||
+ | // getString(ctx, | ||
+ | import static com.mojang.brigadier.arguments.StringArgumentType.getString; | ||
+ | // word() | ||
+ | import static com.mojang.brigadier.arguments.StringArgumentType.word; | ||
+ | // literal(" | ||
+ | import static net.minecraft.server.command.CommandManager.literal; | ||
+ | // argument(" | ||
+ | import static net.minecraft.server.command.CommandManager.argument; | ||
+ | // Import everything | ||
+ | import static net.minecraft.server.command.CommandManager.*; | ||
+ | </ | ||
+ | |||
+ | Note: Please be sure you use the '' | ||
+ | |||
+ | Brigadier' | ||
+ | |||
+ | Minecraft' | ||
+ | CommandManager is in the package '' | ||
==== A sub command ==== | ==== A sub command ==== | ||
Line 94: | Line 118: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | dispatcher.register(CommandManager.literal(" | + | dispatcher.register(literal(" |
- | .then(CommandManager.literal(" | + | .then(literal(" |
); | ); | ||
</ | </ | ||
Line 106: | Line 130: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | dispatcher.register(CommandManager.literal(" | + | dispatcher.register(literal(" |
- | .then(CommandManager.literal(" | + | .then(literal(" |
.executes(context -> { | .executes(context -> { | ||
System.out.println(" | System.out.println(" | ||
Line 142: | Line 166: | ||
public void onInitialize() { | public void onInitialize() { | ||
CommandRegistrationCallback.EVENT.register((dispatcher, | CommandRegistrationCallback.EVENT.register((dispatcher, | ||
- | dispatcher.register(CommandManager.literal(" | + | dispatcher.register(literal(" |
System.out.println(" | System.out.println(" | ||
return 1; | return 1; | ||
Line 188: | Line 212: | ||
**TODO:** Go into more detail on how to use arguments | **TODO:** Go into more detail on how to use arguments | ||
- | |||
- | ===== Static Imports ===== | ||
- | You could type out '' | ||
- | This also works for Minecraft' | ||
- | |||
- | And your imports would look something like this: | ||
- | <code java [enable_line_numbers=" | ||
- | // getString(ctx, | ||
- | import static com.mojang.brigadier.arguments.StringArgumentType.getString; | ||
- | // word() | ||
- | import static com.mojang.brigadier.arguments.StringArgumentType.word; | ||
- | // literal(" | ||
- | import static net.minecraft.server.command.CommandManager.literal; | ||
- | // argument(" | ||
- | import static net.minecraft.server.command.CommandManager.argument; | ||
- | // Import everything | ||
- | import static net.minecraft.server.command.CommandManager.*; | ||
- | </ | ||
- | |||
- | Note: Please be sure you use the '' | ||
- | |||
- | Brigadier' | ||
- | |||
- | Minecraft' | ||
- | CommandManager is in '' | ||
====== Advanced concepts ====== | ====== Advanced concepts ====== | ||
Line 236: | Line 235: | ||
==== Catch or throw a CommandSyntaxException ==== | ==== Catch or throw a CommandSyntaxException ==== | ||
- | The solution to this issue is to make the run or suggest methods throw a CommandSyntaxException. Don't worry, brigadier | + | The solution to this issue is to make the run or suggest methods throw a '' |
==== Issues with generics ==== | ==== Issues with generics ==== | ||
- | You may have an issue with generic types once in a while. Verify you are using '' | + | You may have an issue with generic types once in a while. Verify you are using '' |
===== Can I register client side commands? ===== | ===== Can I register client side commands? ===== | ||
Fabric doesn' | Fabric doesn' | ||
+ | There is an open pull request to fabric api which adds this. That will be documented on this page in the future. | ||
===== Dark Arts ===== | ===== Dark Arts ===== | ||
Line 254: | Line 254: | ||
You can do this but it is not recommended. You would get the '' | You can do this but it is not recommended. You would get the '' | ||
- | After that you 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 unregister commands in runtime? ==== | ==== Can I unregister commands in runtime? ==== |
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210