Search in sources :

Example 1 with ArgumentType

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);
    }
}
Also used : Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Argument(org.spongepowered.api.text.selector.Argument) SelectorType(org.spongepowered.api.text.selector.SelectorType) ArgumentType(org.spongepowered.api.text.selector.ArgumentType) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ArgumentType

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));
}
Also used : SpongeArgumentHolder(org.spongepowered.common.text.selector.SpongeArgumentHolder) ArgumentHolder(org.spongepowered.api.text.selector.ArgumentHolder) ArgumentType(org.spongepowered.api.text.selector.ArgumentType) EntityType(org.spongepowered.api.entity.EntityType) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Vector3d(com.flowpowered.math.vector.Vector3d) SpongeSelectorFactory(org.spongepowered.common.text.selector.SpongeSelectorFactory) Vector3i(com.flowpowered.math.vector.Vector3i)

Example 3 with ArgumentType

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));
}
Also used : LanternArgumentHolder(org.lanternpowered.server.text.selector.LanternArgumentHolder) ArgumentHolder(org.spongepowered.api.text.selector.ArgumentHolder) ArgumentType(org.spongepowered.api.text.selector.ArgumentType) EntityType(org.spongepowered.api.entity.EntityType) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) LanternSelectorFactory(org.lanternpowered.server.text.selector.LanternSelectorFactory) Vector3d(com.flowpowered.math.vector.Vector3d) Vector3i(com.flowpowered.math.vector.Vector3i)

Aggregations

ArgumentType (org.spongepowered.api.text.selector.ArgumentType)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 Vector3i (com.flowpowered.math.vector.Vector3i)2 EntityType (org.spongepowered.api.entity.EntityType)2 GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)2 ArgumentHolder (org.spongepowered.api.text.selector.ArgumentHolder)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LanternArgumentHolder (org.lanternpowered.server.text.selector.LanternArgumentHolder)1 LanternSelectorFactory (org.lanternpowered.server.text.selector.LanternSelectorFactory)1 Argument (org.spongepowered.api.text.selector.Argument)1 SelectorType (org.spongepowered.api.text.selector.SelectorType)1 SpongeArgumentHolder (org.spongepowered.common.text.selector.SpongeArgumentHolder)1 SpongeSelectorFactory (org.spongepowered.common.text.selector.SpongeSelectorFactory)1