本文整理汇总了Java中org.spongepowered.api.text.selector.Selector类的典型用法代码示例。如果您正苦于以下问题:Java Selector类的具体用法?Java Selector怎么用?Java Selector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Selector类属于org.spongepowered.api.text.selector包,在下文中一共展示了Selector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addRotationFilters
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
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()) {
double rmx = rotMinX.get();
filters.add(input -> input.getRotation().getX() >= rmx);
}
Optional<Double> rotMinY = sel.get(ArgumentTypes.ROTATION.minimum().y());
if (rotMinY.isPresent()) {
double rmy = rotMinY.get();
filters.add(input -> input.getRotation().getY() >= rmy);
}
Optional<Double> rotMaxX = sel.get(ArgumentTypes.ROTATION.maximum().x());
if (rotMaxX.isPresent()) {
double rx = rotMaxX.get();
filters.add(input -> input.getRotation().getX() <= rx);
}
Optional<Double> rotMaxY = sel.get(ArgumentTypes.ROTATION.maximum().y());
if (rotMaxY.isPresent()) {
double ry = rotMaxY.get();
filters.add(input -> input.getRotation().getY() <= ry);
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:27,代码来源:SelectorResolver.java
示例2: complete
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Nonnull
@Override
public List<String> complete(
@Nonnull CommandSource src, CommandArgs args, CommandContext context) {
Object state = args.getState();
final Optional<String> nextArg = args.nextIfPresent();
args.setState(state);
List<String> choices = nextArg.map(Selector::complete).orElseGet(ImmutableList::of);
if (choices.isEmpty()) {
choices = super.complete(src, args, context);
}
if (choices.size() == 1) {
currentSurvivalGame = choices.get(0);
} else {
currentSurvivalGame = null;
}
return choices;
}
开发者ID:m0pt0pmatt,项目名称:SurvivalGames,代码行数:22,代码来源:SurvivalGameCommandElement.java
示例3: parseValue
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public ParseResult<ClanPlayer> parseValue(CommandSource commandSource, String value, NormalFilledParameter parameter) {
ClanPlayerImpl clanPlayer = null;
if (value.startsWith("@")) {
Set<Entity> entities = Selector.parse(value).resolve(commandSource);
if (entities.size() > 0 && entities.toArray()[0] instanceof Player) {
UUID uuid = ((Player) entities.toArray()[0]).getUniqueId();
clanPlayer = ClansImpl.getInstance().getClanPlayer(uuid);
} else {
return ParseResult.newErrorResult("Selector produced no results");
}
} else {
clanPlayer = ClansImpl.getInstance().getClanPlayer(value);
}
if (clanPlayer != null) {
return ParseResult.newSuccessResult((ClanPlayer) clanPlayer);
} else {
UUID playerUUID = UUIDUtils.getUUID(value);
Optional<Player> playerOp = playerUUID == null ? Optional.empty() : Sponge.getServer().getPlayer(playerUUID);
if (playerOp.isPresent()) {
return ParseResult.newSuccessResult(ClansImpl.getInstance().createClanPlayer(playerUUID, value));
} else {
return ParseResult.newErrorResult(Messages.PLAYER_DOES_NOT_EXIST);
}
}
}
开发者ID:iLefty,项目名称:mcClans,代码行数:30,代码来源:ClanPlayerParser.java
示例4: deserialize
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@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();
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:JsonTextSelectorSerializer.java
示例5: parseRawSelector
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public Selector parseRawSelector(String selector) {
checkArgument(selector.startsWith("@"), "Invalid selector %s", selector);
// If multi-character types are possible, this handles it
int argListIndex = selector.indexOf('[');
if (argListIndex < 0) {
argListIndex = selector.length();
} else {
int end = selector.indexOf(']');
checkArgument(end > argListIndex && selector.charAt(end - 1) != ',', "Invalid selector %s",
selector);
}
String typeStr = selector.substring(1, argListIndex);
Optional<SelectorType> optSelectorType = this.selectorTypeRegistry.getById(typeStr);
checkArgument(optSelectorType.isPresent(), "No type known as '%s'", typeStr);
try {
Map<String, String> rawMap;
if (argListIndex == selector.length()) {
rawMap = ImmutableMap.of();
} else {
rawMap = this.parseArgumentsMap(selector.substring(argListIndex + 1, selector.length() - 1));
}
Map<ArgumentType<?>, Argument<?>> arguments = parseArguments(rawMap);
return new LanternSelector(optSelectorType.get(), ImmutableMap.copyOf(arguments));
} catch (Exception e) {
throw new IllegalArgumentException("Invalid selector " + selector, e);
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:29,代码来源:LanternSelectorFactory.java
示例6: SelectorResolver
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
private SelectorResolver(Collection<? extends Extent> extents, @Nullable Vector3d position, @Nullable CommandSource original, Selector selector,
boolean force) {
this.extents = ImmutableSet.copyOf(extents);
this.position = position == null ? ORIGIN : position;
this.original = Optional.ofNullable(original);
this.selector = checkNotNull(selector);
this.selectorFilter = makeFilter();
this.alwaysUsePosition = force;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:10,代码来源:SelectorResolver.java
示例7: makeFilter
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
private Predicate<Entity> makeFilter() {
// for easier reading
final Selector sel = this.selector;
final Vector3d position = getPositionOrDefault(this.position, ArgumentTypes.POSITION);
final List<Predicate<Entity>> filters = new ArrayList<>();
addTypeFilters(filters);
addDimensionFilters(position, filters);
addRadiusFilters(position, filters);
addLevelFilters(filters);
addGamemodeFilters(filters);
addNameFilters(filters);
addRotationFilters(filters);
addTeamFilters(filters);
addScoreFilters(filters);
SelectorType selectorType = sel.getType();
final Optional<Argument.Invertible<EntityType>> type = sel.getArgument(ArgumentTypes.ENTITY_TYPE);
// isn't an ALL_ENTITIES selector or it is a RANDOM selector for only players
final 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);
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:28,代码来源:SelectorResolver.java
示例8: addGamemodeFilters
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
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;
});
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:13,代码来源:SelectorResolver.java
示例9: addNameFilters
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
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()));
});
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:13,代码来源:SelectorResolver.java
示例10: addRadiusFilters
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
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);
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:16,代码来源:SelectorResolver.java
示例11: addTypeFilters
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
private void addTypeFilters(List<Predicate<Entity>> filters) {
Selector sel = this.selector;
Optional<Argument.Invertible<EntityType>> typeOpt = sel.getArgument(ArgumentTypes.ENTITY_TYPE);
if (typeOpt.isPresent()) {
Argument.Invertible<EntityType> typeArg = typeOpt.get();
boolean inverted = typeArg.isInverted();
EntityType type = typeArg.getValue();
filters.add(input -> inverted ^ input.getType() == type);
}
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:SelectorResolver.java
示例12: add
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public Selector.Builder add(Argument<?>... arguments) {
for (Argument<?> argument : checkNotNull(arguments, "arguments")) {
checkNotNull(argument, "argument");
this.arguments.put(argument.getType(), argument);
}
return this;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternSelectorBuilder.java
示例13: remove
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public Selector.Builder remove(Argument<?>... arguments) {
for (Argument<?> argument : checkNotNull(arguments, "arguments")) {
checkNotNull(argument, "argument");
this.arguments.remove(argument.getType());
}
return this;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternSelectorBuilder.java
示例14: processSelector
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@SuppressWarnings("unused")
private boolean processSelector(final CommandSource source, final String argument) throws CommandException, PluginDisableException, ServerDisableException, EMessageException {
int start = -1;
int cpt = -1;
int open = 0;
boolean type = false;
for (char c : argument.toCharArray()) {
cpt++;
if (start == -1) {
if (c != '@') continue;
if (cpt != 0 && argument.charAt(cpt-1) != ' ') continue;
start = cpt;
} else if (cpt == start + 1) {
if (this.plugin.getGame().getRegistry().getAllOf(SelectorType.class).stream().filter(t -> t.getName().equals(String.valueOf(c))).findAny().isPresent()) {
type = true;
} else {
start = -1;
}
} else if (cpt == start + 2) {
if (c == ' ') {
cpt--;
break;
}
if (c == '[') {
open = 1;
} else {
start = -1;
type = false;
}
} else {
if (c == '[') {
open++;
} else if (c == ']') {
open--;
if (open == 0) {
break;
}
}
}
}
if (start != -1 && open == 0 && type) {
String stringSelector = argument.substring(start, cpt+1);
String first = (start == 0) ? "" : argument.substring(0, start);
String last = (cpt+1 == argument.length()) ? "" : argument.substring(cpt+1, argument.length());
try {
List<Entity> players = new ArrayList<Entity>(Selector.parse(stringSelector).resolve(source));
players.removeIf(entity -> !(entity instanceof Player));
if (players.isEmpty()) return false;
for (Entity player : players) {
this.processExecute(source, first + ((Player) player).getName() + last);
}
return true;
} catch (IllegalArgumentException e) {}
}
return false;
}
开发者ID:EverCraft,项目名称:EverAPI,代码行数:63,代码来源:ECommand.java
示例15: createBuilder
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public Selector.Builder createBuilder() {
return new LanternSelectorBuilder();
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternSelectorFactory.java
示例16: addScoreFilters
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
private void addScoreFilters(List<Predicate<Entity>> filters) {
Selector sel = this.selector;
sel.getArguments();
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:SelectorResolver.java
示例17: LanternSelectorBuilder
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
public LanternSelectorBuilder(Selector selector) {
this.from(selector);
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:LanternSelectorBuilder.java
示例18: build
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public Selector build() {
checkState(this.type != null, "type is not set");
return new LanternSelector(this.type, ImmutableMap.copyOf(this.arguments));
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:6,代码来源:LanternSelectorBuilder.java
示例19: from
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public Selector.Builder from(Selector selector) {
this.type = selector.getType();
this.arguments = Maps.newLinkedHashMap(((LanternSelector) selector).arguments);
return this;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:LanternSelectorBuilder.java
示例20: reset
import org.spongepowered.api.text.selector.Selector; //导入依赖的package包/类
@Override
public Selector.Builder reset() {
this.type = null;
this.arguments = Maps.newLinkedHashMap();
return this;
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:LanternSelectorBuilder.java
注:本文中的org.spongepowered.api.text.selector.Selector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论