Prevents #getRandomPlayer from throwing an Exception on 0 online players

This commit is contained in:
Christian Koop 2021-10-02 14:58:14 +02:00
parent ce72ab7291
commit 9605ac5ded
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3

View File

@ -162,12 +162,18 @@ public class PlayerUtils {
public static Player getRandomPlayer() {
final Collection<? extends Player> all = Bukkit.getOnlinePlayers();
if (all.isEmpty()) {
return null;
}
final Iterator<? extends Player> alli = all.iterator();
int pick = random.nextInt(all.size());
for (; pick > 0; --pick) {
alli.next();
}
return alli.hasNext() ? alli.next() : null;
return alli.next();
}
public static void giveItem(Player player, ItemStack item) {