Fixed casting issues and more boolean issues

This commit is contained in:
Andrew 2013-11-06 04:56:23 +13:00
parent a48db82eb9
commit f431b619fe

View File

@ -147,19 +147,23 @@ public abstract class BaseDisguiseCommand implements CommandExecutor {
Class param = types[0]; Class param = types[0];
if (float.class == param || double.class == param || int.class == param) { if (float.class == param || double.class == param || int.class == param) {
if (isDouble(valueString)) { if (isDouble(valueString)) {
value = param.cast(Float.parseFloat(valueString)); float obj = Float.parseFloat(valueString);
if (param == float.class) {
value = (float) obj;
} else if (param == int.class) {
value = (int) obj;
} else if (param == double.class) {
value = (double) obj;
}
} else { } else {
throw new Exception(ChatColor.RED + "Expected a number, received " + valueString throw new Exception(ChatColor.RED + "Expected a number, received " + valueString
+ " instead for " + methodName); + " instead for " + methodName);
} }
} else if (boolean.class == param) { } else if (boolean.class == param) {
try { if (!("true".equalsIgnoreCase(valueString) || "false".equalsIgnoreCase(valueString)))
Boolean.parseBoolean(valueString);
} catch (Exception ex) {
throw new Exception(ChatColor.RED + "Expected true/false, received " + valueString throw new Exception(ChatColor.RED + "Expected true/false, received " + valueString
+ " instead for " + methodName); + " instead for " + methodName);
} value = (boolean) "true".equalsIgnoreCase(valueString);
value = param.cast(Boolean.parseBoolean(valueString));
} else if (param == String.class) { } else if (param == String.class) {
value = valueString; value = valueString;
} }