command system
This commit is contained in:
parent
a8f6af2b37
commit
a891ab4d3a
11 changed files with 361 additions and 87 deletions
|
@ -1,11 +1,26 @@
|
|||
package game.command;
|
||||
|
||||
import game.world.Position;
|
||||
|
||||
public class DoubleParser extends DefaultingParser {
|
||||
public static enum DefType {
|
||||
X, Y, Z, YAW, PITCH;
|
||||
}
|
||||
|
||||
private final DefType defType;
|
||||
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.defType = null;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public DoubleParser(String name, DefType type, Double min, Double max, Object ... completions) {
|
||||
super(name, null, completions);
|
||||
this.defType = type;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
@ -30,4 +45,21 @@ public class DoubleParser extends DefaultingParser {
|
|||
throw new ScriptException("Die Zahl darf höchstens %f betragen, habe %f", this.max, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
public Double getDefault(ScriptEnvironment env) {
|
||||
Position pos = this.defType == null ? null : env.getExecutor().getExecPos();
|
||||
switch(this.defType) {
|
||||
case X:
|
||||
return pos == null ? null : pos.x;
|
||||
case Y:
|
||||
return pos == null ? null : pos.y;
|
||||
case Z:
|
||||
return pos == null ? null : pos.z;
|
||||
case YAW:
|
||||
return pos == null ? null : (double)pos.yaw;
|
||||
case PITCH:
|
||||
return pos == null ? null : (double)pos.pitch;
|
||||
}
|
||||
return (Double)super.getDefault(env);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue