Hey all, just wondering, how can I code a message that tells the player how many players are online when they join? Thanks.
Bukkit.getOnlinePlayers().size() EDIT: It might be Bukkit.getOnlinePlayers().length depending on what build you use IIRC
you have to set an OnPlayerJoin event, then get the Bukkit.getOnlinePlayers().size() / Bukkit.getOnlinePlayers().lenght to display the amount of online player at the moment. And by the way " it doesn't work " isn't a valid awnser, you should try discribing the problem in more details -Nic
@Nic2555 Indeed. @john2342 is this "doesnt work" a Runtime error? a Compilation error? Also if we could see your code it woundt be bad.
Code: @EventHandler public void onJoin(PlayerJoinEvent e){ Player p = (Player) e.getPlayer(); p.sendMessage("There are " + Bukkit.getServer().getOnlinePlayers().size() + " out of " + Bukkit.getServer().getMaxPlayers()); } }
Here is a work-around for getting the online players size (1.7 & 1.8!): Code: int onlineCount = 0; for (Player online : Bukkit.getOnlinePlayers()) onlineCount++; //code