Try all methods before giving up. Fixes duplicate methods = Funny errors

This commit is contained in:
libraryaddict 2014-09-15 01:27:50 +12:00
parent c21e1b00ff
commit 304558cc6e

@ -456,22 +456,19 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
String valueString = (args.length - 1 == i ? null : args[i + 1]);
Method methodToUse = null;
Object value = null;
Exception storedEx = null;
for (Method method : methods) {
if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName)
&& method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) {
try {
methodToUse = method;
break;
}
}
if (methodToUse == null) {
throw new Exception(ChatColor.RED + "Cannot find the option " + methodName);
}
methodName = methodToUse.getName();
Class<?>[] types = methodToUse.getParameterTypes();
Class param = types[0];
if (boolean.class == param) {
// Parse to boolean
if (valueString == null || !("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) {
if (valueString == null
|| !("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString))) {
value = true;
i--;
} else {
@ -585,6 +582,19 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
}
}
}
break;
} catch (Exception ex) {
methodToUse = null;
storedEx = ex;
}
}
}
if (methodToUse == null) {
if (storedEx != null) {
throw storedEx;
}
throw new Exception(ChatColor.RED + "Cannot find the option " + methodName);
}
if (!usedOptions.contains(methodName.toLowerCase())) {
usedOptions.add(methodName.toLowerCase());
}