package game.command; public class LongParser extends DefaultingParser { private final Long min; private final Long max; public LongParser(String name, Long def, Long min, Long max, Object ... completions) { super(name, def, completions); this.min = min; this.max = max; } public Long parse(ScriptEnvironment env, String input) { long value; try { value = Long.parseLong(input); } catch(NumberFormatException e) { throw new ScriptException("Ungültige Ganzzahl '%s'", input); } if(this.min != null && value < this.min) if(this.max != null) throw new ScriptException("Die Zahl muss im Bereich %d .. %d liegen, habe %d", this.min, this.max, value); else throw new ScriptException("Die Zahl muss mindestens %d betragen, habe %d", this.min, value); if(this.max != null && value > this.max) if(this.min != null) throw new ScriptException("Die Zahl muss im Bereich %d .. %d liegen, habe %d", this.min, this.max, value); else throw new ScriptException("Die Zahl darf höchstens %d betragen, habe %d", this.max, value); return value; } public Class getTypeClass() { return this.hasDefault() ? long.class : Long.class; } }