java - Java - CommandSender 类型未定义适用于此处的 getName(Object)
问题描述
我有这个错误:
这是该行中的代码错误:
sender.sendMessage(ConfigurationService.GRAY + Joiner.on(", ").join((Iterable)playerList.stream().map((Function<? super Object, ?>)CommandSender::getName).collect((Collector<? super Object, ?, List<? super Object>>)Collectors.toList())));
完整代码
public class NearCommand implements CommandExecutor
{
public static final int RADIUS = 30;
private final HCF hcf;
public NearCommand(final HCF hcf) {
this.hcf = hcf;
}
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (sender instanceof Player) {
final Player player = (Player)sender;
final List<Player> playerList = this.getNearbyEnemies(player);
if (playerList.isEmpty()) {
sender.sendMessage(ConfigurationService.YELLOW + "There are no visible enemies in a " + 30 + " block radius");
}
else {
sender.sendMessage(ConfigurationService.YELLOW + "Nearby visible enemies in a " + 30 + " block radius");
sender.sendMessage(ConfigurationService.GRAY + Joiner.on(", ").join((Iterable)playerList.stream().map((Function<? super Object, ?>)CommandSender::getName).collect((Collector<? super Object, ?, List<? super Object>>)Collectors.toList())));
}
}
else {
sender.sendMessage(ConfigurationService.RED + "You need to be a player to do this");
}
return true;
}
public List<Player> getNearbyEnemies(final Player player) {
final List<Player> players = new ArrayList<Player>();
final FactionManager factionManager = this.hcf.getFactionManager();
final Faction playerFaction = factionManager.getPlayerFaction(player.getUniqueId());
final Collection<Entity> nearby = (Collection<Entity>)player.getNearbyEntities(30.0, 30.0, 30.0);
for (final Entity entity : nearby) {
if (entity instanceof Player) {
final Player target = (Player)entity;
if (!target.canSee(player)) {
continue;
}
if (!player.canSee(target)) {
continue;
}
if (target.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
continue;
}
final Faction targetFaction;
if (playerFaction != null && (targetFaction = factionManager.getPlayerFaction(target)) != null && targetFaction.equals(playerFaction)) {
continue;
}
players.add(target);
}
}
return players;
}
这是 bukkit 的一个类别,我需要帮助。
解决方案
推荐阅读
- android - 有没有办法强制 Glide 只从缓存加载图像,而不是从网络加载图像?
- typescript - 打字稿中是否有像 python 中的 __setattr__ 这样的函数?
- string - 使用Matlab查找字符串中包含的子字符串
- c# - 使用未分配的变量“格式”、“attr1”、“attr2”、“attr3”
- javascript - 通过 Firestore 文档的对象数组“映射”时出错。(React-Redux)
- python - model.predict() - 精度接近 1 的模型预测错误的类别
- amazon-web-services - 如何控制 Hive-On-Tez 中的容器数量
- r - 重复循环中 data.table v1.13.0 的性能问题
- python - 使用 regex_extract 循环遍历字符串列表 Pyspark
- c++ - 使用 libvpx 的实时 VP9 编码