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;
});
}
}
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);
}
}
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();
}
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();
}
});
}
}
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();
});
}
}
Aggregations