Fix up basecommand and booleans

This commit is contained in:
libraryaddict 2014-09-27 15:41:30 +12:00
parent ddac7feda3
commit 702a58c3bf

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
import me.libraryaddict.disguise.disguisetypes.Disguise;
@ -473,11 +474,15 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
Method methodToUse = null;
Object value = null;
DisguiseParseException storedEx = null;
for (Method method : methods) {
if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName)
&& method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) {
int c = 0;
while (c < methods.length) {
try {
methodToUse = method;
Entry<Method, Integer> entry = getMethod(methods, methodName, c);
if (entry == null) {
break;
}
methodToUse = entry.getKey();
c = entry.getValue();
methodName = methodToUse.getName();
Class<?>[] types = methodToUse.getParameterTypes();
Class param = types[0];
@ -594,8 +599,14 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
value = true;
} else if (valueString.equalsIgnoreCase("false")) {
value = false;
} else
} else {
if (getMethod(methods, valueString, 0) == null) {
throw parseToException("true/false", valueString, methodName);
} else {
value = true;
i--;
}
}
}
if (value != null) {
break;
@ -608,7 +619,6 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
methodToUse = null;
}
}
}
if (methodToUse == null) {
if (storedEx != null) {
throw storedEx;
@ -631,6 +641,17 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
return disguise;
}
private Entry<Method, Integer> getMethod(Method[] methods, String methodName, int toStart) {
for (int i = toStart; i < methods.length; i++) {
Method method = methods[i];
if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName)
&& method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) {
return new HashMap.SimpleEntry(method, ++i);
}
}
return null;
}
private Object callValueOf(Class<?> param, String valueString, String methodName, String description)
throws DisguiseParseException {
Object value;