Skip to content

Commit

Permalink
Selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Nov 16, 2020
1 parent 8adc644 commit fea1b48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,19 @@ private boolean validateRanking(CommandSender sender, PlayerData state, String a
}

private List<Player> getPlayers(CommandSender sender, List<String> args) {
List<Player> players = new ArrayList<>();
String arg0 = get(args, 0);
if (arg0 == null)
players.add((Player) sender);
else if ("@a".equals(arg0))
players.addAll(Bukkit.getOnlinePlayers());
else if ("@p".equals(arg0)) {
Location loc = (sender instanceof BlockCommandSender)
? ((BlockCommandSender) sender).getBlock().getLocation()
: (sender instanceof Entity)
? ((Entity) sender).getLocation()
: null;
if (loc != null)
loc.getNearbyPlayers(32, e -> !e.equals(sender)).stream()
.min(Comparator.comparing(e -> loc.distanceSquared(e.getLocation())))
.ifPresent(players::add);
} else
players.addAll(args.stream().map(Bukkit::getPlayer).filter(Objects::nonNull).collect(Collectors.toList()));
return players;
try {
return Bukkit.selectEntities(sender, String.join(" ", args)).stream()
.filter(Player.class::isInstance)
.map(Player.class::cast)
.collect(Collectors.toList());
} catch (IllegalArgumentException e) {
sender.sendMessage(new ComponentBuilder()
.append("[かめすたプラグイン] ").color(ChatColor.LIGHT_PURPLE)
.append("セレクターが間違っています").color(ChatColor.RED)
.create()
);
}
return Collections.emptyList();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/romaji.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ o,お
?,?
,,、
(,(
(,)
),)
[,「
],」
.,。
Expand Down

0 comments on commit fea1b48

Please sign in to comment.