cn.nukkit.command.selector.args.impl.Name Maven / Gradle / Ivy
package cn.nukkit.command.selector.args.impl;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.selector.ParseUtils;
import cn.nukkit.command.selector.SelectorType;
import cn.nukkit.command.selector.args.CachedSimpleSelectorArgument;
import cn.nukkit.entity.Entity;
import cn.nukkit.level.Location;
import java.util.ArrayList;
import java.util.function.Predicate;
@PowerNukkitXOnly
@Since("1.19.60-r1")
public class Name extends CachedSimpleSelectorArgument {
@Override
protected Predicate cache(SelectorType selectorType, CommandSender sender, Location basePos, String... arguments) {
final var have = new ArrayList();
final var dontHave = new ArrayList();
for (var name : arguments) {
boolean reversed = ParseUtils.checkReversed(name);
if (reversed) {
name = name.substring(1);
dontHave.add(name);
} else have.add(name);
}
return entity -> have.stream().allMatch(name -> entity.getName().equals(name)) && dontHave.stream().noneMatch(name -> entity.getName().equals(name));
}
@Override
public String getKeyName() {
return "name";
}
@Override
public int getPriority() {
return 4;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy