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 revisionBoth sides next revision
tutorial:commands [2020/05/16 01:57] – Reword some parts of the tutorial, includes a few gramatical corrections i509vcbtutorial:commands [2020/06/14 01:12] – Reword static imports section i509vcb
Line 83: Line 83:
  
 ==== Static Imports ==== ==== Static Imports ====
-You could do the long method of typing ''CommandManager.literal("foo")'' and it would work, but you can statically import the arguments and shorten that to ''literal("foo")'' +You could type out ''CommandManager.literal("foo")'' every time you want to create a literal. This works, but you can statically import the arguments and shorten the statement to ''literal("foo")''. This also works for getting the value of an argument. This shortens ''StringArgumentType.getString(ctx, "string")'' to ''getString(ctx, "string")''
-This also works for getting arguments, which shortens the already long ''StringArgumentType.getString(ctx, "string")'' to ''getString(ctx, "string")''+This also works for Minecraft'own argument types.
-This also works for Minecraft'arguments.+
  
 And your imports would look something like this: And your imports would look something like this:
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-import static com.mojang.brigadier.arguments.StringArgumentType.getString; // getString(ctx, "string"+// getString(ctx, "string"
-import static com.mojang.brigadier.arguments.StringArgumentType.word; // word(), string(), greedyString() +import static com.mojang.brigadier.arguments.StringArgumentType.getString; 
-import static net.minecraft.server.command.CommandManager.literal; // literal("foo") +// word() 
-import static net.minecraft.server.command.CommandManager.argument; // argument("bar", word()) +import static com.mojang.brigadier.arguments.StringArgumentType.word; 
-import static net.minecraft.server.command.CommandManager.*; // Import everything+ // literal("foo"
 +import static net.minecraft.server.command.CommandManager.literal; 
 + // argument("bar", word()
 +import static net.minecraft.server.command.CommandManager.argument; 
 +// Import everything 
 +import static net.minecraft.server.command.CommandManager.*;
 </code> </code>
  
-Note: Please be sure you use the ''literal'' and ''argument'' from CommandManager or you may have issues with generics.+Note: Please be sure you use the ''literal'' and ''argument'' from CommandManager or you may have issues with generics when trying to compile.
  
-Brigadier's default arguments are located in ''com.mojang.brigadier.arguments''+Brigadier's default arguments are at ''com.mojang.brigadier.arguments''
  
-Minecraft's arguments hide in ''net.minecraft.command.arguments'' and the CommandManager is at ''net.minecraft.server.command''+Minecraft's arguments are in ''net.minecraft.command.arguments''
 +CommandManager is in ''net.minecraft.server.command''
  
 ==== Suggestions ==== ==== Suggestions ====
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210