Split TNTRandomRangeValidator into two validators
This commit is contained in:
1 file changed
+14
-8
@@ -89,24 +89,30 @@ public class CarpetSettings
|
||||
@Rule( desc = "TNT causes less lag when exploding in the same spot and in liquids", category = TNT)
|
||||
public static boolean optimizedTNT = false;
|
||||
|
||||
private static class CheckOptimizedTntEnabledValidator<T> extends Validator<T> {
|
||||
@Override
|
||||
public T validate(ServerCommandSource source, ParsedRule<T> currentRule, T newValue, String string) {
|
||||
return optimizedTNT || currentRule.defaultValue.equals(newValue) ? newValue : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "optimizedTNT must be enabled";
|
||||
}
|
||||
}
|
||||
|
||||
@Rule( desc = "Sets the tnt random explosion range to a fixed value", category = TNT, options = "-1",
|
||||
validate = TNTRandomRangeValidator.class, extra = "Set to -1 for default behavior")
|
||||
validate = {CheckOptimizedTntEnabledValidator.class, TNTRandomRangeValidator.class}, extra = "Set to -1 for default behavior")
|
||||
public static double tntRandomRange = -1;
|
||||
|
||||
private static class TNTRandomRangeValidator extends Validator<Double> {
|
||||
@Override
|
||||
public Double validate(ServerCommandSource source, ParsedRule<Double> currentRule, Double newValue, String string) {
|
||||
if (newValue == -1)
|
||||
return newValue;
|
||||
if (!optimizedTNT)
|
||||
return null;
|
||||
return newValue >= 0 ? newValue : null;
|
||||
return newValue == -1 || newValue >= 0 ? newValue : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
if (!optimizedTNT)
|
||||
return "Requires optimizedTNT to be enabled";
|
||||
return "Cannot be negative, except for -1";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user