Search in sources :

Example 6 with Selector

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

the class SelectorResolver method addGamemodeFilters.

private void addGamemodeFilters(List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    Optional<GameMode> gamemode = sel.get(ArgumentTypes.GAME_MODE);
    // If the game mode is NOT_SET, that means accept any
    if (gamemode.isPresent() && gamemode.get() != GameModes.NOT_SET) {
        final GameMode actualMode = gamemode.get();
        filters.add(input -> {
            Optional<GameModeData> mode = input.get(GameModeData.class);
            return mode.isPresent() && mode.get() == actualMode;
        });
    }
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) GameModeData(org.spongepowered.api.data.manipulator.mutable.entity.GameModeData) Selector(org.spongepowered.api.text.selector.Selector)

Example 7 with Selector

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

the class SelectorResolver method addRadiusFilters.

private void addRadiusFilters(final Vector3d position, List<Predicate<Entity>> filters) {
    final Selector sel = this.selector;
    Optional<Integer> radiusMin = sel.get(ArgumentTypes.RADIUS.minimum());
    Optional<Integer> radiusMax = sel.get(ArgumentTypes.RADIUS.maximum());
    if (radiusMin.isPresent()) {
        int radMin = radiusMin.get();
        int radMinSquared = radMin * radMin;
        filters.add(input -> input.getLocation().getPosition().distanceSquared(position) >= radMinSquared);
    }
    if (radiusMax.isPresent()) {
        int radMax = radiusMax.get();
        int radMaxSquared = radMax * radMax;
        filters.add(input -> input.getLocation().getPosition().distanceSquared(position) <= radMaxSquared);
    }
}
Also used : Selector(org.spongepowered.api.text.selector.Selector)

Example 8 with Selector

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

the class SelectorResolver method addScoreFilters.

private void addScoreFilters(List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    sel.getArguments();
}
Also used : Selector(org.spongepowered.api.text.selector.Selector)

Example 9 with Selector

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

the class SelectorResolver method addTeamFilters.

private void addTeamFilters(List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    Optional<Invertible<String>> teamOpt = sel.getArgument(ArgumentTypes.TEAM);
    if (teamOpt.isPresent()) {
        Invertible<String> teamArg = teamOpt.get();
        final boolean inverted = teamArg.isInverted();
        final Collection<Team> teams = Sponge.getGame().getServer().getServerScoreboard().get().getTeams();
        filters.add(new Predicate<Entity>() {

            @Override
            public boolean test(Entity input) {
                if (input instanceof TeamMember) {
                    return inverted ^ collectMembers(teams).contains(((TeamMember) input).getTeamRepresentation());
                }
                return false;
            }

            private Collection<Text> collectMembers(Collection<Team> teams) {
                ImmutableSet.Builder<Text> users = ImmutableSet.builder();
                for (Team t : teams) {
                    users.addAll(t.getMembers());
                }
                return users.build();
            }
        });
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) TeamMember(org.spongepowered.api.scoreboard.TeamMember) Collection(java.util.Collection) Team(org.spongepowered.api.scoreboard.Team) Invertible(org.spongepowered.api.text.selector.Argument.Invertible) Selector(org.spongepowered.api.text.selector.Selector)

Example 10 with Selector

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

the class SelectorResolver method addDimensionFilters.

private void addDimensionFilters(final Vector3d position, List<Predicate<Entity>> filters) {
    Selector sel = this.selector;
    Vector3d boxDimensions = getPositionOrDefault(ORIGIN, ArgumentTypes.DIMENSION);
    Vector3d det2 = position.add(boxDimensions);
    final Vector3d boxMin = position.min(det2);
    final Vector3d boxMax = position.max(det2);
    if (sel.has(ArgumentTypes.DIMENSION.x())) {
        filters.add(input -> {
            Vector3d pos = input.getLocation().getPosition();
            return pos.getX() >= boxMin.getX() && pos.getX() <= boxMax.getX();
        });
    }
    if (sel.has(ArgumentTypes.DIMENSION.y())) {
        filters.add(input -> {
            Vector3d pos = input.getLocation().getPosition();
            return pos.getY() >= boxMin.getY() && pos.getY() <= boxMax.getY();
        });
    }
    if (sel.has(ArgumentTypes.DIMENSION.z())) {
        filters.add(input -> {
            Vector3d pos = input.getLocation().getPosition();
            return pos.getZ() >= boxMin.getZ() && pos.getZ() <= boxMax.getZ();
        });
    }
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) 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