PlayersType implements StringType<List<Player>> { @Override public List<Player> parse(StringReader reader) throws CommandSyntaxException { var argument = reader.peek() == '"' ? reader.readQuotedString() : Readers.until(reader, ' '); if (argument.equalsIgnoreCase("@a")) { return online(); } var online = online(); var players = new ArrayList<Player>(); var names = Readers.COMMA.split(argument); for (var name : names) { if (name.equalsIgnoreCase("@r")) { players.add(online.get(ThreadLocalRandom.current().nextInt(online.size()))); continue; } var player = server.getPlayerExact(name); if (player != null) { players.add(player); } else if (name.equalsIgnoreCase("@a")) { throw INVALID.createWithContext(reader); } else { throw UNKNOWN.createWithContext(reader, name); } } return players; } PlayersType(); @Override List<Player> parse(StringReader reader); @Override CompletableFuture<Suggestions> listSuggestions(S source, CommandContext<S> context, SuggestionsBuilder builder); @Override List<String> getExamples();  }
@Test void parse_throws_invalid_exception() { assertEquals( "'@a' cannot be used in a list of players.", assertThrows(CommandSyntaxException.class, () -> type.parse(new StringReader("\"@a, Pante\""))).getRawMessage().toString() ); }
@Test void parse_throws_unknown_exception() { assertEquals( "Unknown player or selector: invalid", assertThrows(CommandSyntaxException.class, () -> type.parse(new StringReader("invalid"))).getRawMessage().toString() ); }