use of org.spongepowered.api.text.selector.Selector in project LanternServer by LanternPowered.
the class JsonTextSelectorSerializer method deserialize.
@Override
public SelectorText deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
final JsonObject obj = json.getAsJsonObject();
final Selector selector = Selector.parse(obj.get(SELECTOR).getAsString());
final SelectorText.Builder builder = SelectorText.builder(selector);
deserialize(obj, builder, context);
return builder.build();
}
use of org.spongepowered.api.text.selector.Selector 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();
}
});
}
}
use of org.spongepowered.api.text.selector.Selector in project SpongeCommon by SpongePowered.
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 gamemode 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 SpongeCommon by SpongePowered.
the class SelectorResolver method addLevelFilters.
private void addLevelFilters(List<Predicate<Entity>> filters) {
Selector sel = this.selector;
Optional<Integer> levelMin = sel.get(ArgumentTypes.LEVEL.minimum());
Optional<Integer> levelMax = sel.get(ArgumentTypes.LEVEL.maximum());
if (levelMin.isPresent()) {
final int actualMin = levelMin.get();
filters.add(input -> {
Optional<ExperienceHolderData> xp = input.get(ExperienceHolderData.class);
return xp.isPresent() && xp.get().level().get() >= actualMin;
});
}
if (levelMax.isPresent()) {
final int actualMax = levelMax.get();
filters.add(input -> {
Optional<ExperienceHolderData> xp = input.get(ExperienceHolderData.class);
return xp.isPresent() && xp.get().level().get() <= actualMax;
});
}
}
use of org.spongepowered.api.text.selector.Selector in project SpongeCommon by SpongePowered.
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()) {
final double rmx = rotMinX.get();
filters.add(input -> input.getRotation().getX() >= rmx);
}
Optional<Double> rotMinY = sel.get(ArgumentTypes.ROTATION.minimum().y());
if (rotMinY.isPresent()) {
final double rmy = rotMinY.get();
filters.add(input -> input.getRotation().getY() >= rmy);
}
Optional<Double> rotMaxX = sel.get(ArgumentTypes.ROTATION.maximum().x());
if (rotMaxX.isPresent()) {
final double rx = rotMaxX.get();
filters.add(input -> input.getRotation().getX() <= rx);
}
Optional<Double> rotMaxY = sel.get(ArgumentTypes.ROTATION.maximum().y());
if (rotMaxY.isPresent()) {
final double ry = rotMaxY.get();
filters.add(input -> input.getRotation().getY() <= ry);
}
}
Aggregations