Solved Getting Number of Online Players

Discussion in 'Plugin Development' started by KeybordPiano459, Dec 23, 2012.

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

    KeybordPiano459

    Is there a better way to get the number of online players than this?
    Code:java
    1. @SuppressWarnings("unused")
    2. public int onlinePlayers() {
    3. int a = 0;
    4.  
    5. for (Player player : getServer().getOnlinePlayers()) {
    6. a++;
    7. }
    8.  
    9. return a;
    10. }
     
  2. Offline

    xGamingDudex

    Bukkit.getOnlinePlayers().length;
     
  3. Offline

    ImDeJay

    Code:
    int blah = this.getServer().getOnlinePlayers().length;
     
  4. Offline

    KeybordPiano459

    How did i not know that =/ thanks :)
     
  5. Offline

    moodoggy

    Ahh Jack you noob
     
  6. Offline

    CeramicTitan

    I think your using the wrong for loop.

    Try for(a=0;a=Bukkit.getServer().getOnlinePlayers().length; a++){
    //do stuff
    }
    return a;
    }
    }

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  7. Offline

    fireblast709

    No his foreach loop was good enough. Though its better to just use .length to get the amount of online players.
     
Thread Status:
Not open for further replies.

Share This Page