Search in sources :

Example 1 with TeamMember

use of org.spongepowered.api.scoreboard.TeamMember 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 2 with TeamMember

use of org.spongepowered.api.scoreboard.TeamMember in project SpongeCommon by SpongePowered.

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)

Aggregations

Collection (java.util.Collection)2 Entity (org.spongepowered.api.entity.Entity)2 Team (org.spongepowered.api.scoreboard.Team)2 TeamMember (org.spongepowered.api.scoreboard.TeamMember)2 Invertible (org.spongepowered.api.text.selector.Argument.Invertible)2 Selector (org.spongepowered.api.text.selector.Selector)2