Player count?

Discussion in 'Plugin Development' started by john2342, Jul 24, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    Hey all, just wondering, how can I code a message that tells the player how many players are online when they join? Thanks.
  2. Offline

    The Fancy Whale

    EDIT: It might be Bukkit.getOnlinePlayers().length depending on what build you use IIRC
  3. Offline


    Thanks! Yeah used .length before but now it doesn't work.
  4. Offline


    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 :)

  5. Offline


    @Nic2555 Indeed.

    @john2342 is this "doesnt work" a Runtime error? a Compilation error?
    Also if we could see your code it woundt be bad.
  6. Offline


        public void onJoin(PlayerJoinEvent e){
            Player p = (Player) e.getPlayer();
            p.sendMessage("There are " + Bukkit.getServer().getOnlinePlayers().size() + " out of " + Bukkit.getServer().getMaxPlayers());
  7. Here is a work-around for getting the online players size (1.7 & 1.8!):
    int onlineCount = 0;
    for (Player online : Bukkit.getOnlinePlayers()) onlineCount++;
Thread Status:
Not open for further replies.

Share This Page