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/11/25 08:20] – [Advanced concepts] i509vcbtutorial:commands [2021/03/07 20:27] modmuss50
Line 237: Line 237:
 ==== 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''. Brigadier will handle the checked exceptions and forward the proper error message in game for you.+The solution to this issue is to make the ''run'' or ''suggest'' methods throw a ''CommandSyntaxException''. Brigadier will handle the checked exceptions and forward the proper error message in game for you.
  
 ==== Issues with generics ==== ==== Issues with generics ====
Line 245: Line 245:
 ===== Can I register client side commands? ===== ===== Can I register client side commands? =====
  
-Fabric doesn't currently support client side commands. There is [[https://github.com/CottonMC/ClientCommands|third-party mod]] by the Cotton team that adds this functionality. +Fabric has ClientCommandManager that can be used to register client side commands.
-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 280: Line 279:
  .requires(source -> source.hasPermissionLevel(4))  .requires(source -> source.hasPermissionLevel(4))
  .executes(ctx -> {  .executes(ctx -> {
- ctx.getSource().sendFeedback(new LiteralText("You are an operator", false));+ ctx.getSource().sendFeedback(new LiteralText("You are an operator"), false);
  return 1;  return 1;
  });  });
Line 425: Line 424:
  
 public static int broadcast(ServerCommandSource source, Formatting formatting, String message) { public static int broadcast(ServerCommandSource source, Formatting formatting, String message) {
-    final Text text = new LiteralText(message).formatting(formatting);+    final Text text = new LiteralText(message).formatted(formatting);
  
-    source.getMinecraftServer().getPlayerManager().broadcastChatMessage(text, false);+    source.getMinecraftServer().getPlayerManager().broadcastChatMessage(text, MessageType.CHAT, source.getPlayer().getUuid());
     return Command.SINGLE_SUCCESS; // Success     return Command.SINGLE_SUCCESS; // Success
 } }
tutorial/commands.txt · Last modified: 2024/02/23 14:22 by allen1210