use of org.spongepowered.api.text.selector.ArgumentType in project SpongeCommon by SpongePowered.
the class SpongeSelectorFactory method parseRawSelector.
@Override
public Selector parseRawSelector(String selector) {
checkArgument(selector.startsWith("@"), "Invalid selector %s", selector);
// If multi-character types are possible, this handles it
int argListIndex = selector.indexOf('[');
if (argListIndex < 0) {
argListIndex = selector.length();
} else {
int end = selector.indexOf(']');
checkArgument(end > argListIndex && selector.charAt(end - 1) != ',', "Invalid selector %s", selector);
}
String typeStr = selector.substring(1, argListIndex);
checkArgument(idToType.containsKey(typeStr), "No type known as '%s'", typeStr);
SelectorType type = idToType.get(typeStr);
try {
Map<String, String> rawMap;
if (argListIndex == selector.length()) {
rawMap = ImmutableMap.of();
} else {
rawMap = EntitySelector.getArgumentMap(selector.substring(argListIndex + 1, selector.length() - 1));
}
Map<ArgumentType<?>, Argument<?>> arguments = parseArguments(rawMap);
return new SpongeSelector(type, ImmutableMap.copyOf(arguments));
} catch (Exception e) {
throw new IllegalArgumentException("Invalid selector " + selector, e);
}
}
use of org.spongepowered.api.text.selector.ArgumentType in project SpongeCommon by SpongePowered.
the class ArgumentRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
final SpongeSelectorFactory factory = SpongeImpl.getRegistry().getSelectorFactory();
// POSITION
ArgumentType<Integer> x = factory.createArgumentType("x", Integer.class);
ArgumentType<Integer> y = factory.createArgumentType("y", Integer.class);
ArgumentType<Integer> z = factory.createArgumentType("z", Integer.class);
ArgumentHolder.Vector3<Vector3i, Integer> position = new SpongeArgumentHolder.SpongeVector3<>(x, y, z, Vector3i.class);
this.argumentTypeMap.put("position", position);
// RADIUS
ArgumentType<Integer> rmin = factory.createArgumentType("rm", Integer.class);
ArgumentType<Integer> rmax = factory.createArgumentType("r", Integer.class);
ArgumentHolder.Limit<ArgumentType<Integer>> radius = new SpongeArgumentHolder.SpongeLimit<>(rmin, rmax);
this.argumentTypeMap.put("radius", radius);
// GAME_MODE
this.argumentTypeMap.put("game_mode", factory.createArgumentType("m", GameMode.class));
// COUNT
this.argumentTypeMap.put("count", factory.createArgumentType("c", Integer.class));
// LEVEL
ArgumentType<Integer> lmin = factory.createArgumentType("lm", Integer.class);
ArgumentType<Integer> lmax = factory.createArgumentType("l", Integer.class);
ArgumentHolder.Limit<ArgumentType<Integer>> level = new SpongeArgumentHolder.SpongeLimit<>(lmin, lmax);
this.argumentTypeMap.put("level", level);
// TEAM
this.argumentTypeMap.put("team", factory.createInvertibleArgumentType("team", Integer.class, org.spongepowered.api.scoreboard.Team.class.getName()));
// NAME
this.argumentTypeMap.put("name", factory.createInvertibleArgumentType("name", String.class));
// DIMENSION
ArgumentType<Integer> dx = factory.createArgumentType("dx", Integer.class);
ArgumentType<Integer> dy = factory.createArgumentType("dy", Integer.class);
ArgumentType<Integer> dz = factory.createArgumentType("dz", Integer.class);
ArgumentHolder.Vector3<Vector3i, Integer> dimension = new SpongeArgumentHolder.SpongeVector3<>(dx, dy, dz, Vector3i.class);
this.argumentTypeMap.put("dimension", dimension);
// ROTATION
ArgumentType<Double> rotxmin = factory.createArgumentType("rxm", Double.class);
ArgumentType<Double> rotymin = factory.createArgumentType("rym", Double.class);
ArgumentType<Double> rotzmin = factory.createArgumentType("rzm", Double.class);
ArgumentHolder.Vector3<Vector3d, Double> rotmin = new SpongeArgumentHolder.SpongeVector3<>(rotxmin, rotymin, rotzmin, Vector3d.class);
ArgumentType<Double> rotxmax = factory.createArgumentType("rx", Double.class);
ArgumentType<Double> rotymax = factory.createArgumentType("ry", Double.class);
ArgumentType<Double> rotzmax = factory.createArgumentType("rz", Double.class);
ArgumentHolder.Vector3<Vector3d, Double> rotmax = new SpongeArgumentHolder.SpongeVector3<>(rotxmax, rotymax, rotzmax, Vector3d.class);
ArgumentHolder.Limit<ArgumentHolder.Vector3<Vector3d, Double>> rot = new SpongeArgumentHolder.SpongeLimit<>(rotmin, rotmax);
this.argumentTypeMap.put("rotation", rot);
// ENTITY_TYPE
this.argumentTypeMap.put("entity_type", factory.createInvertibleArgumentType("type", EntityType.class));
}
use of org.spongepowered.api.text.selector.ArgumentType in project LanternServer by LanternPowered.
the class ArgumentTypeRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
@SuppressWarnings("deprecation") final LanternSelectorFactory factory = Lantern.getGame().getRegistry().getSelectorFactory();
// POSITION
ArgumentType<Integer> x = factory.createArgumentType("x", Integer.class);
ArgumentType<Integer> y = factory.createArgumentType("y", Integer.class);
ArgumentType<Integer> z = factory.createArgumentType("z", Integer.class);
ArgumentHolder.Vector3<Vector3i, Integer> position = new LanternArgumentHolder.LanternVector3<>(x, y, z, Vector3i.class);
this.argumentTypeMap.put("position", position);
// RADIUS
ArgumentType<Integer> rmin = factory.createArgumentType("rm", Integer.class);
ArgumentType<Integer> rmax = factory.createArgumentType("r", Integer.class);
ArgumentHolder.Limit<ArgumentType<Integer>> radius = new LanternArgumentHolder.LanternLimit<>(rmin, rmax);
this.argumentTypeMap.put("radius", radius);
// GAME_MODE
this.argumentTypeMap.put("game_mode", factory.createArgumentType("m", GameMode.class));
// COUNT
this.argumentTypeMap.put("count", factory.createArgumentType("c", Integer.class));
// LEVEL
ArgumentType<Integer> lmin = factory.createArgumentType("lm", Integer.class);
ArgumentType<Integer> lmax = factory.createArgumentType("l", Integer.class);
ArgumentHolder.Limit<ArgumentType<Integer>> level = new LanternArgumentHolder.LanternLimit<>(lmin, lmax);
this.argumentTypeMap.put("level", level);
// TEAM
this.argumentTypeMap.put("team", factory.createInvertibleArgumentType("team", Integer.class, org.spongepowered.api.scoreboard.Team.class.getName()));
// NAME
this.argumentTypeMap.put("name", factory.createInvertibleArgumentType("name", String.class));
// DIMENSION
ArgumentType<Integer> dx = factory.createArgumentType("dx", Integer.class);
ArgumentType<Integer> dy = factory.createArgumentType("dy", Integer.class);
ArgumentType<Integer> dz = factory.createArgumentType("dz", Integer.class);
ArgumentHolder.Vector3<Vector3i, Integer> dimension = new LanternArgumentHolder.LanternVector3<>(dx, dy, dz, Vector3i.class);
this.argumentTypeMap.put("dimension", dimension);
// ROTATION
ArgumentType<Double> rotxmin = factory.createArgumentType("rxm", Double.class);
ArgumentType<Double> rotymin = factory.createArgumentType("rym", Double.class);
ArgumentType<Double> rotzmin = factory.createArgumentType("rzm", Double.class);
ArgumentHolder.Vector3<Vector3d, Double> rotmin = new LanternArgumentHolder.LanternVector3<>(rotxmin, rotymin, rotzmin, Vector3d.class);
ArgumentType<Double> rotxmax = factory.createArgumentType("rx", Double.class);
ArgumentType<Double> rotymax = factory.createArgumentType("ry", Double.class);
ArgumentType<Double> rotzmax = factory.createArgumentType("rz", Double.class);
ArgumentHolder.Vector3<Vector3d, Double> rotmax = new LanternArgumentHolder.LanternVector3<>(rotxmax, rotymax, rotzmax, Vector3d.class);
ArgumentHolder.Limit<ArgumentHolder.Vector3<Vector3d, Double>> rot = new LanternArgumentHolder.LanternLimit<>(rotmin, rotmax);
this.argumentTypeMap.put("rotation", rot);
// ENTITY_TYPE
this.argumentTypeMap.put("entity_type", factory.createInvertibleArgumentType("type", EntityType.class));
}
Aggregations