Extracted some hardcoded strings to constants

This commit is contained in:
Nathan Adams 2014-10-13 12:18:42 +02:00
parent 91559191b6
commit b6b684efc7
2 changed files with 14 additions and 6 deletions

View file

@ -28,6 +28,11 @@ public class CommandDispatcher<T> {
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<T> {
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();

View file

@ -7,6 +7,9 @@ import com.mojang.brigadier.context.ParsedArgument;
import com.mojang.brigadier.exceptions.CommandException;
public class ArgumentCommandNode<T> extends CommandNode {
private static final String USAGE_ARGUMENT_OPEN = "<";
private static final String USAGE_ARGUMENT_CLOSE = ">";
private final String name;
private final CommandArgumentType<T> type;
@ -31,7 +34,7 @@ public class ArgumentCommandNode<T> extends CommandNode {
@Override
public String getUsageText() {
return "<" + name + ">";
return USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE;
}
@Override