Try avoid letting people use stupid values for numbers. Fixes #635

This commit is contained in:
libraryaddict 2022-01-17 16:43:03 +13:00
parent 69a5628f76
commit 18081cf1ba
5 changed files with 45 additions and 34 deletions

View File

@ -17,7 +17,13 @@ public class ParamInfoDouble extends ParamInfo {
@Override
protected Object fromString(String string) {
return Double.parseDouble(string);
double result = Double.parseDouble(string);
if (!Double.isFinite(result) || Math.abs(result) > 999_999_999) {
throw new NumberFormatException("For input string: \"" + string + "\"");
}
return result;
}
@Override

View File

@ -7,12 +7,22 @@ import me.libraryaddict.disguise.utilities.params.ParamInfo;
*/
public class ParamInfoFloat extends ParamInfo {
public ParamInfoFloat(String name, String description) {
super(float.class, name, description);
this(float.class, name, description);
}
public ParamInfoFloat(Class cl, String name, String description) {
super(cl, name, description);
}
@Override
protected Object fromString(String string) {
return Float.parseFloat(string);
float result = Float.parseFloat(string);
if (!Float.isFinite(result) || Math.abs(result) > 999_999_999) {
throw new NumberFormatException("For input string: \"" + string + "\"");
}
return result;
}
@Override

View File

@ -5,7 +5,7 @@ import me.libraryaddict.disguise.utilities.params.ParamInfo;
/**
* Created by libraryaddict on 7/09/2018.
*/
public class ParamInfoFloatNullable extends ParamInfo {
public class ParamInfoFloatNullable extends ParamInfoFloat {
public ParamInfoFloatNullable(String name, String description) {
super(Float.class, name, description);
}
@ -16,7 +16,7 @@ public class ParamInfoFloatNullable extends ParamInfo {
return null;
}
return Float.parseFloat(string);
return super.fromString(string);
}
@Override

View File

@ -143,6 +143,11 @@ public class ParamInfoParticle extends ParamInfoEnum {
throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string);
} else {
size = Math.max(0.2f, Float.parseFloat(split[split.length - 1]));
// Stupid high cap
if (size > 100) {
size = 100;
}
}
data = new Particle.DustOptions(color, size);

View File

@ -108,13 +108,13 @@ public class DisguiseParser {
}
if (getMethod == null) {
DisguiseUtilities.getLogger().severe(String
.format("No such method '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(),
DisguiseUtilities.getLogger().severe(
String.format("No such method '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(),
setMethod.getWatcherClass().getSimpleName()));
continue;
} else if (getMethod.getReturnType() != setMethod.getParam()) {
DisguiseUtilities.getLogger().severe(String
.format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(),
DisguiseUtilities.getLogger().severe(
String.format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(),
setMethod.getWatcherClass().getSimpleName()));
continue;
}
@ -298,8 +298,7 @@ public class DisguiseParser {
if (!Objects.deepEquals(dObj, object)) {
throw new IllegalStateException(String.format(
"%s has conflicting values in class %s! This means it expected the same value again but " + "received a " +
"different value on a different disguise! %s is not the same as %s!", setMethod.toString(), setMethod.toString(), object,
dObj));
"different value on a different disguise! %s is not the same as %s!", setMethod.toString(), setMethod.toString(), object, dObj));
}
return;
@ -416,15 +415,6 @@ public class DisguiseParser {
return new DisguisePermissions(sender, commandName);
}
private static boolean isDouble(String string) {
try {
Float.parseFloat(string);
return true;
} catch (Exception ex) {
return false;
}
}
private static boolean isInteger(String string) {
try {
Integer.parseInt(string);