use of org.spongepowered.api.text.selector.Selector 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.Selector in project SpongeCommon by SpongePowered.
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 SpongeCommon by SpongePowered.
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 det1 = position;
Vector3d det2 = position.add(boxDimensions);
final Vector3d boxMin = det1.min(det2);
final Vector3d boxMax = det1.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();
});
}
}
use of org.spongepowered.api.text.selector.Selector in project LanternServer by LanternPowered.
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 LanternServer by LanternPowered.
the class SelectorResolver method addNameFilters.
private void addNameFilters(List<Predicate<Entity>> filters) {
Selector sel = this.selector;
Optional<Argument.Invertible<String>> nameOpt = sel.getArgument(ArgumentTypes.NAME);
if (nameOpt.isPresent()) {
final String name = nameOpt.get().getValue();
final boolean inverted = nameOpt.get().isInverted();
filters.add(input -> {
Optional<DisplayNameData> dispName = input.get(DisplayNameData.class);
return inverted ^ (dispName.isPresent() && name.equals(dispName.get().displayName().get().toPlain()));
});
}
}
Aggregations