Allow boolean params to not require a argument to be true

This commit is contained in:
libraryaddict 2014-06-14 20:55:28 +12:00
parent 61d8ca7b42
commit e940a9e0e9

View File

@ -335,10 +335,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
args = newArgs; args = newArgs;
for (int i = 0; i < args.length; i += 2) { for (int i = 0; i < args.length; i += 2) {
String methodName = args[i]; String methodName = args[i];
if (i + 1 >= args.length) { String valueString = (args.length - 1 == i ? null : args[i + 1]);
throw new Exception(ChatColor.RED + "No value was given for the option " + methodName);
}
String valueString = args[i + 1];
Method methodToUse = null; Method methodToUse = null;
Object value = null; Object value = null;
for (Method method : disguise.getWatcher().getClass().getMethods()) { for (Method method : disguise.getWatcher().getClass().getMethods()) {
@ -355,6 +352,18 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
Class<?>[] types = methodToUse.getParameterTypes(); Class<?>[] types = methodToUse.getParameterTypes();
if (types.length == 1) { if (types.length == 1) {
Class param = types[0]; Class param = types[0];
if (boolean.class == param) {
// Parse to boolean
if (valueString == null || !("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) {
value = true;
i--;
} else {
value = "true".equalsIgnoreCase(valueString);
}
} else {
if (valueString == null) {
throw new Exception(ChatColor.RED + "No value was given for the option " + methodName);
}
if (int.class == param) { if (int.class == param) {
// Parse to integer // Parse to integer
if (isNumeric(valueString)) { if (isNumeric(valueString)) {
@ -374,11 +383,6 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} else { } else {
throw parseToException("number.0", valueString, methodName); throw parseToException("number.0", valueString, methodName);
} }
} else if (boolean.class == param) {
// Parse to boolean
if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString)))
throw parseToException("true/false", valueString, methodName);
value = (boolean) "true".equalsIgnoreCase(valueString);
} else if (param == String.class) { } else if (param == String.class) {
// Parse to string // Parse to string
value = ChatColor.translateAlternateColorCodes('&', valueString); value = ChatColor.translateAlternateColorCodes('&', valueString);
@ -444,6 +448,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
} }
} }
} }
}
if (!usedOptions.contains(methodName.toLowerCase())) { if (!usedOptions.contains(methodName.toLowerCase())) {
usedOptions.add(methodName.toLowerCase()); usedOptions.add(methodName.toLowerCase());
} }