initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
33
java/src/game/command/DoubleParser.java
Normal file
33
java/src/game/command/DoubleParser.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue