Search in sources :

Example 21 with Selector

use of org.spongepowered.api.text.selector.Selector in project LanternServer by LanternPowered.

the class SelectorResolver method addTypeFilters.

private void addTypeFilters(List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    Optional<Argument.Invertible<EntityType>> typeOpt = sel.getArgument(ArgumentTypes.ENTITY_TYPE);
    if (typeOpt.isPresent()) {
        Argument.Invertible<EntityType> typeArg = typeOpt.get();
        boolean inverted = typeArg.isInverted();
        EntityType type = typeArg.getValue();
        filters.add(input -> inverted ^ input.getType() == type);
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Argument(org.spongepowered.api.text.selector.Argument) Invertible(org.spongepowered.api.text.selector.Argument.Invertible) Selector(org.spongepowered.api.text.selector.Selector)

Example 22 with Selector

use of org.spongepowered.api.text.selector.Selector in project LanternServer by LanternPowered.

the class SelectorResolver method addRotationFilters.

private void addRotationFilters(List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    // If the Z's are uncommented, don't forget to implement them
    // Optional<Double> rotMinZ = sel.get(ArgumentTypes.ROTATION.minimum().z());
    // Optional<Double> rotMaxZ = sel.get(ArgumentTypes.ROTATION.maximum().z());
    Optional<Double> rotMinX = sel.get(ArgumentTypes.ROTATION.minimum().x());
    if (rotMinX.isPresent()) {
        double rmx = rotMinX.get();
        filters.add(input -> input.getRotation().getX() >= rmx);
    }
    Optional<Double> rotMinY = sel.get(ArgumentTypes.ROTATION.minimum().y());
    if (rotMinY.isPresent()) {
        double rmy = rotMinY.get();
        filters.add(input -> input.getRotation().getY() >= rmy);
    }
    Optional<Double> rotMaxX = sel.get(ArgumentTypes.ROTATION.maximum().x());
    if (rotMaxX.isPresent()) {
        double rx = rotMaxX.get();
        filters.add(input -> input.getRotation().getX() <= rx);
    }
    Optional<Double> rotMaxY = sel.get(ArgumentTypes.ROTATION.maximum().y());
    if (rotMaxY.isPresent()) {
        double ry = rotMaxY.get();
        filters.add(input -> input.getRotation().getY() <= ry);
    }
}
Also used : Selector(org.spongepowered.api.text.selector.Selector)

Aggregations

Selector (org.spongepowered.api.text.selector.Selector)22 Invertible (org.spongepowered.api.text.selector.Argument.Invertible)8 Vector3d (com.flowpowered.math.vector.Vector3d)4 Entity (org.spongepowered.api.entity.Entity)4 Collection (java.util.Collection)2 Predicate (java.util.function.Predicate)2 DisplayNameData (org.spongepowered.api.data.manipulator.mutable.DisplayNameData)2 ExperienceHolderData (org.spongepowered.api.data.manipulator.mutable.entity.ExperienceHolderData)2 GameModeData (org.spongepowered.api.data.manipulator.mutable.entity.GameModeData)2 EntityType (org.spongepowered.api.entity.EntityType)2 Player (org.spongepowered.api.entity.living.player.Player)2 GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)2 Team (org.spongepowered.api.scoreboard.Team)2 TeamMember (org.spongepowered.api.scoreboard.TeamMember)2 Argument (org.spongepowered.api.text.selector.Argument)2 SelectorType (org.spongepowered.api.text.selector.SelectorType)2 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Score (org.spongepowered.api.scoreboard.Score)1 SelectorText (org.spongepowered.api.text.SelectorText)1