Fix up basecommand and booleans

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

View File

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