use of org.spongepowered.api.text.selector.Argument.Invertible in project SpongeCommon by SpongePowered.
the class SelectorResolver method makeFilter.
private Predicate<Entity> makeFilter() {
// for easier reading
final Selector sel = this.selector;
Vector3d position = getPositionOrDefault(this.position, ArgumentTypes.POSITION);
List<Predicate<Entity>> filters = Lists.newArrayList();
addTypeFilters(filters);
addDimensionFilters(position, filters);
addRadiusFilters(position, filters);
addLevelFilters(filters);
addGamemodeFilters(filters);
addNameFilters(filters);
addRotationFilters(filters);
addTeamFilters(filters);
addScoreFilters(filters);
SelectorType selectorType = sel.getType();
Optional<Invertible<EntityType>> type = sel.getArgument(ArgumentTypes.ENTITY_TYPE);
// isn't an ALL_ENTITIES selector or it is a RANDOM selector for only players
boolean isPlayerOnlySelector = selectorType == SelectorTypes.ALL_PLAYERS || selectorType == SelectorTypes.NEAREST_PLAYER || (selectorType == SelectorTypes.RANDOM && type.isPresent() && !type.get().isInverted() && type.get().getValue() != EntityTypes.PLAYER);
if (isPlayerOnlySelector) {
// insert at the start so it applies first
filters.add(0, requireTypePredicate(Entity.class, Player.class));
}
return Functional.predicateAnd(filters);
}
use of org.spongepowered.api.text.selector.Argument.Invertible 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();
}
});
}
}
use of org.spongepowered.api.text.selector.Argument.Invertible 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();
}
});
}
}
Aggregations