getOnlinePlayers() method like

Discussion in 'Plugin Development' started by xMalwarez, Sep 17, 2014.

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

    xMalwarez

    Good evening,

    I know the version 1.7.9_R0.3 longer has getOnlinePlayers () but I like to know if there was any way to retrieve online players in a list otherwise?

    Have a nice evening.
     
  2. xMalwarez
    I haven't used the newer versions yet, but from what I can remember, it was changed to a Collection and is still there.
     
  3. Offline

    xMalwarez

    Assist
    I can not find the collection lol
     
  4. xMalwarez
    Just checked the docs, the old method is deprecated and a new one was added, returns a Collection<Player>.
     
  5. Offline

    xMalwarez

  6. Offline

    Garris0n

    You don't find what?

    The method is there, and it returns a collection. How can you "not find" the method?
     
  7. Offline

    xMalwarez

    Code:java
    1. Collection<? extends Player> players = Bukkit.getOnlinePlayers();


    Is don't work
     
  8. Offline

    bennie3211

    Bukkit.getOnlinePlayers() does work for me with 1.7.10
     
  9. Offline

    fireblast709

    bennie3211 no, you will find that something like
    Code:
    Player[] players = Bukkit.getOnlinePlayers();
    Won't work. Try
    Code:
    Collection<Player> players = Bukkit.getOnlinePlayers();
     
  10. Offline

    indyetoile

    xMalwarez
    Alternatively, you could use
    Code:java
    1. ArrayList<Player> onlineplayers = new ArrayList<Player>();
    2. for(Player p : Bukkit.getOnlinePlayers){
    3. onlineplayers.add(p);
    4. }
    to add all the players to an ArrayList, but using fireblast709 's method is probably what you're looking for.
     
  11. Offline

    fireblast709

    indyetoile And why exactly would you want to do that :p
     
  12. Offline

    indyetoile

  13. Offline

    teej107

    If that is how your doing it, at least do this:
    Code:java
    1. List<Player> players = new ArrayList<Player>(Bukkit.getOnlinePlayers());
    Btw don't do this.
     
  14. Too many resources. Gotta waste them somehow.
     
    rbrick likes this.
  15. AdamQpzm you could read in all uuid's which are saved into the files from bukkit and use bukkit.getplayer(uuid). if it returns null, the player is offline i think. also you should fore the server to save all players/uuids into its files to make sure that nobody joined new and no file had been created for him until the timepoint you try to load all players. maybe you can fore the server to do that with a reload or there could be a method which does that. idk

    AdamQpzm i saw it while i was programming on my own server.savePlayers() will safe every player to playername.dat. then you can get the path of the files by getting the path of your running plugin and switch it over to the playerfolder. then read all uuids out of the playerfiles and use server.getplayer(uuid) if it returns null, the player is offline, else you will get the player. this is how you could do it without using getOnlinePlayers. but why don't you want to use getOnlinePlayers?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  16. Shmobi Who said I didn't want to?
     
  17. AdamQpzm well ... my fault! :D im sorry, for some reason i thought you are the creator of this thread. wuuuupsi :D
     
    AdamQpzm likes this.
  18. Offline

    Awesomedanguy

    Why not Bukkit.getOnlinePlayers().toString();

    Please correct me if I'm wrong ;)
     
  19. Offline

    teej107

    That would be getting the string returned by the method of the collection. Not the players inside of it.
     
  20. Offline

    Awesomedanguy

    Oh :p Silly me, thanks for telling me :) teej107
     
Thread Status:
Not open for further replies.

Share This Page