diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 5158b46..a9fdbd4 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -28,6 +28,11 @@ public class CommandDispatcher { public static final SimpleCommandExceptionType ERROR_UNKNOWN_COMMAND = new SimpleCommandExceptionType("unknown_command", "Unknown command"); public static final String ARGUMENT_SEPARATOR = " "; + private static final String USAGE_OPTIONAL_OPEN = "["; + private static final String USAGE_OPTIONAL_CLOSE = "]"; + private static final String USAGE_REQUIRED_OPEN = "("; + private static final String USAGE_REQUIRED_CLOSE = ")"; + private static final String USAGE_OR = "|"; private final RootCommandNode root = new RootCommandNode(); @@ -88,23 +93,23 @@ public class CommandDispatcher { StringBuilder result = new StringBuilder(context.getInput()); result.append(ARGUMENT_SEPARATOR); if (optional) { - result.append("["); + result.append(USAGE_OPTIONAL_OPEN); } else if (children.size() > 1) { - result.append("("); + result.append(USAGE_REQUIRED_OPEN); } for (int i = 0; i < children.size(); i++) { result.append(children.get(i).getUsageText()); if (i < children.size() - 1) { - result.append("|"); + result.append(USAGE_OR); } } if (optional) { - result.append("]"); + result.append(USAGE_OPTIONAL_CLOSE); } else if (children.size() > 1) { - result.append(")"); + result.append(USAGE_REQUIRED_CLOSE); } return result.toString(); diff --git a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java index 540e8bc..008bc25 100644 --- a/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/ArgumentCommandNode.java @@ -7,6 +7,9 @@ import com.mojang.brigadier.context.ParsedArgument; import com.mojang.brigadier.exceptions.CommandException; public class ArgumentCommandNode extends CommandNode { + private static final String USAGE_ARGUMENT_OPEN = "<"; + private static final String USAGE_ARGUMENT_CLOSE = ">"; + private final String name; private final CommandArgumentType type; @@ -31,7 +34,7 @@ public class ArgumentCommandNode extends CommandNode { @Override public String getUsageText() { - return "<" + name + ">"; + return USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE; } @Override