mirror of
https://github.com/songoda/SongodaCore.git
synced 2025-02-03 05:01:27 +01:00
Prevents #getRandomPlayer from throwing an Exception on 0 online players
This commit is contained in:
parent
ce72ab7291
commit
9605ac5ded
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user