initial commit

This commit is contained in:
Sen 2025-03-11 00:23:54 +01:00 committed by Sen
parent 3c9ee26b06
commit 22186c33b9
1458 changed files with 282792 additions and 0 deletions

View file

@ -0,0 +1,33 @@
package game.command;
public class DoubleParser extends DefaultingParser {
private final Double min;
private final Double max;
public DoubleParser(String name, Double def, Double min, Double max, Object ... completions) {
super(name, def, completions);
this.min = min;
this.max = max;
}
public Double parse(ScriptEnvironment env, String input) {
double value;
try {
value = Double.parseDouble(input);
}
catch(NumberFormatException e) {
throw new ScriptException("Ungültige Gleitkommazahl '%s'", input);
}
if(this.min != null && value < this.min)
if(this.max != null)
throw new ScriptException("Die Zahl muss im Bereich %f .. %f liegen, habe %f", this.min, this.max, value);
else
throw new ScriptException("Die Zahl muss mindestens %f betragen, habe %f", this.min, value);
if(this.max != null && value > this.max)
if(this.min != null)
throw new ScriptException("Die Zahl muss im Bereich %f .. %f liegen, habe %f", this.min, this.max, value);
else
throw new ScriptException("Die Zahl darf höchstens %f betragen, habe %f", this.max, value);
return value;
}
}