Player count?

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

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

    john2342

    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

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

    john2342

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

    Nic2555

    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
     
  5. Offline

    mine-care

    @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

    WPM

    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());
        }
    }
     
  7. 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
     
Thread Status:
Not open for further replies.

Share This Page