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:53] – Populate advanced concepts table i509vcbtutorial:commands [2020/06/14 05:13] – Refactor FAQ section i509vcb
Line 212: Line 212:
 CommandManager is in ''net.minecraft.server.command'' CommandManager is in ''net.minecraft.server.command''
  
-===== 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.
Line 225: Line 225:
  
 **TODO:** Sections are being moved to sub categories and will be added to their respective articles as they are migrated. **TODO:** Sections are being moved to sub categories and will be added to their respective articles as they are migrated.
 +
 +====== Sorry for the mess ======
 +
 +__Currently this article is being migrated, so things may be a mess. Below is are the parts of the article that are yet to be migrated to the new format.__
  
 ===== Requirements ===== ===== Requirements =====
Line 591: Line 595:
 } }
 </file> </file>
-===== 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 to the CommandSource? ===+The solution to this issue is to make the run or suggest methods throw a CommandSyntaxException. Don't worry, brigadier will handle the exceptions and output the proper error message.
  
-You use the Text classes (LiteralText, TranslatableText, KeybindText, etc).+==== Issues with generics ====
  
-=== Why does my IDE complain saying that method executed by my command needs to catch or throw a CommandSyntaxException ===+You may have an issue with generic types once in while. Verify you are using ''CommandManager.literal(...)'' or ''CommandManager.argument(...)'' instead ''LiteralArgumentBuilder'' or ''RequiredArgumentBuilder''.
  
-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 commands in runtime? ===+Fabric doesn't currently support client side commands. There is a [[https://github.com/CottonMC/ClientCommands|third-party mod]] by the Cotton team that adds this functionality.
  
-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 ''CommandManager.sendCommandTree(ServerPlayerEntity)''+A few things we don't recommend, but are possible.
  
-=== Can I unregister commands in runtime? ===+==== Can I register commands in runtime? ====
  
-You can also do this but it is very unstable and could cause unwanted side effectsLets just say it involves a bunch of Reflection.+You can do this but it is not recommendedYou would get the ''CommandManager'' from the server and add anything commands you wish to it's ''CommandDispatcher''.
  
-Once again you will need to send the command tree to every player again using ''CommandManager.sendCommandTree(ServerPlayerEntity)'' afterwards.+After that you need to send the command tree to every player again using ''sendCommandTree(ServerPlayerEntity)''. This is required because the client locally caches the command tree it receives during login (or when operator packets are sent) for local completions rich error messages.
  
-=== Can I register client side commands? ===+==== Can I unregister commands in runtime====
  
-Well Fabric currently doesn't support this natively but there is a mod by the Cotton team that adds this functionality where the commands do not run on the server and only on the client+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 the nodes. After this, you need to send the command tree to every player again using ''sendCommandTree(ServerPlayerEntity)''. If you don't send the updated command tree, the client may think a command still exists, even though the server will fail execution.
-https://github.com/CottonMC/ClientCommands+
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210