Get Server online players?

Discussion in 'Plugin Development' started by andrewginn, Apr 6, 2016.

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

    andrewginn

    Hi there,

    I am new to coding and have noticed that bukkit.getonlineplayers() is deprecated now, is there an alternative to this command or will I have to go to scrap a find a new way. If anyone has the answer that would be great!
     
    Last edited: Apr 6, 2016
  2. Offline

    Kage0x3B

  3. Offline

    Gonmarte

    Deprecated only means that you should avoid it, doesnt mean that is broken. So, you can still use it.
     
    Last edited: Apr 6, 2016
  4. Offline

    CraftCreeper6

    Deprecated*

    @andrewginn Defecated means to release faeces from your body.

    Decreapted isn't even a word, so I haven't a clue.

    Also, deprecated doesn't mean doesn't work, just means it will likely be removed in a future version.
     
  5. Offline

    Gonmarte

    Fixed the name.
     
  6. Offline

    andrewginn

    Oh god xD Sorry @CraftCreeper6 @Gonmarte also do u guys know the line of code for this? That website the guy gave me made me even more confused
     
  7. Offline

    CraftCreeper6

    @andrewginn
    @Kage0x3B gave a valid link, Spigot has a #getOnlinePlayers() method that isn't deprecated. He's telling you to use Spigot.
     
  8. Offline

    Gonmarte

    We are not going to spoonfeed you, if you want code go to the Plugin Requests section.
    If you want to get all the online players in the server, make a for each loop, looping though all the online players. If you dont know what a for each loop is, i advice you to learn java before man an attempt on bukkit.
    @CraftCreeper6 Doesnt matter it its deprecated or no. It still works.
     
  9. Offline

    CraftCreeper6

    @Gonmarte
     
  10. Offline

    Gonmarte

    Im just saying he doesnt need to use the spigot api for this.
     
  11. Offline

    CraftCreeper6

    @Gonmarte
    I am aware of this, but if he wants to remove the deprecation warning without adding the annotation then that's the only way.
     
    Gonmarte likes this.
  12. Offline

    mcdorli

    Isn't there a getServer().getOnlinePlayers() method?
     
    Gonmarte likes this.
  13. Offline

    andrewginn

    I understand that and I don't want to be spoon fed, I was asking because I was wondering if there was a single line code exactly the same that I might be missing out on, and I do know what for loops are it's just when I put them into my code with the bukkit terminology I get confused, for instance knowing a for each loop is simple, but knowing what bukkit codes when you don't have a clue is the hard part. So if you could tell me in words, not in code on where I could find these bukkit codes for for looping I will be very grateful. @CraftCreeper6 @Gonmarte
     
  14. Offline

    Gonmarte

    The problem is that @andrewginn maybe its not ready for coding bukkit. I have seen yesterday, he asking help to learn java, in a forum here, and he learnt "everything" (of course its not everything) in 1 day?
    Just saying, that he might wanna take a deep look in java again.

    @andrewginn
    I have already told you. getOnlinePlayers() returns a collection (if im not mistake) of players. So you need to loop thought that collection. Take a look at this - http://www.tutorialspoint.com/javaexamples/method_for.htm
    Correct me if its not a collection pls.
     
  15. Offline

    andrewginn

    @mcdorli I tried that man I get a red line underneath it like I did with the bukkit.getonlineplayers() code

    @Gonmarte I of course didn't learn everything, I sat there for many hours straight learning the variables and if statements increment operators specific loops methods and instances, but guess what learning bukkit is a whole new world also, and if I haven't researched that well I guess we came to the point in time which is now. Also why are you telling me what to do? This is my life and I have taken interest in a hobby I would love to do, people recommend oh read java don't watch it but I did read it and I read it ALOT, so please if you could help me out that would be fantastic instead of dictating my life and telling me what to do.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 6, 2016
  16. Offline

    Gonmarte

    Take a look pls
    Code:
    //You need to put the "" in the names, im to lazy :p
    String[] players = {Gonmarte, mcdorli, andrewginn, Notch, Zombie, Kapa};
    //We have our array that contains all the online players (lets say)
    //We wanna loop thought it.
    for (String playerName : players){
      //Code that you wanna run each loop
      // In the first loop, player name = Gonmarte
      // Second mcdorli etc
    }
    
    The only difference is that the object is a player and not strings.
    And you need to invoce the getOnlinePlayers() method.
    Remeber this was not spoonfeed, only a java example so you can understand.
    If you dont understand, learn java please.
     
  17. Offline

    andrewginn

    @Gonmarte I understand this is the for looping method, the problem is by what you mean by the getOnlinePlayers() method, You have made a arraylist which will then be looped and the on the right hand side of the colon you have put the object which is players which will then every time it loops will say the names in order only 1 per loop.
     
  18. Offline

    Zombie_Striker

    @Gonmarte @CraftCreeper6
    Spigot is not going to remove those methods for quite some time. He really should use the .getOnlinePlayers() method, even if it is deprecated. The annotation should not be a deterrent.

    @andrewginn
    Use Bukkit.getOnlinePlayers() to return a collection of all the player's online. Use the .size method on that collection to return the amount of contents in the collection (I.E how many players are online).
     
    Gonmarte likes this.
  19. Offline

    andrewginn

    @Zombie_Striker Just a question how do I return the collection of the code? Everyone who has said that has got me hugely confused, if you could explain that would be great!
     
  20. Offline

    Gonmarte

    As @Zombie_Striker said .size will return the size of the collection, for another workds, the amount of online players.
    But if you want interact with each players, you need to use a for each loop.
    So what you wanna do?
    Its an array, not an arraylist.
    Use the player as the object and the method getOnlinePlayers() and my array are both collections, so see the way i loop through mine, and loop through getOnlinePlayers the samw way
     
  21. Offline

    andrewginn

    @Gonmarte I am making a plugin so when someone types /staff they get a message with all the online staff members using variables in the sender.sendmessage, therefore I need the bukkit.getOnlinePlayers() so I can gather the info of the players.
     
  22. Offline

    Gonmarte

    Its obvious that you dont know what a collection is.
    getBukkitPlayers() is the same as
    Code:
    Player[] p = {//Everytime a player enter in the server, its added to here, everytime the player leaves its removed.};
    
    So instead of writing p in your for each loop you write the method.
     
  23. Offline

    CraftCreeper6

    @Zombie_Striker
    Argh, I know he can still use it :) Hence why I never said he shouldn't, Spigot is an alternative that he could use to remove the deprecation, however, still works using Bukkit anyway.
     
  24. Offline

    Zombie_Striker

    Nope. Because arrays are not collections. They share the same idea (storing multiple instances in one instance), but they are two different types of objects.

    You can't learn Java by making plugins. This is a great example of why that is. You won't know how to some basic things in Java if you never officially learned Java before. Please find a tutorial at the following link, learn Java (should take close to a week), and come back to Bukkit. Everything should make sense after you do that:
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/

    Use Collection's .size() method to get the amount of object in the collection.
     
  25. Offline

    ShowbizLocket61

    I must disagree with you on that. It's quite possible, just that one needs to search things up in the proper places (ie. StackOverflow) rather than post questions regarding concepts.
     
  26. Offline

    andrewginn

    @Gonmarte Oh my god, it is obvious I don't know what a collection is because I said it!! Anyways I think I get the gist of it, so I replace the players which would be your example for each loop and replace the players with the .getOnlinePlayers() method.
     
  27. Offline

    mcdorli

    Then LEARN JAVA (I feel posting a link to a java tutorial is close to unneccesary as he already got them.)
     
  28. Offline

    andrewginn

    I know most the basics since I have taken it up before just I didn't have time for it, I'm asking on here so I can refresh my brain and obviously coding changes over time, I have already seen and visited that thread plenty a times, the problem is something has changed and I didn't know how to approach it so I came here, but now I understand from @Gonmarte 's explanation.

    @mcdorli This isn't a thread wether or not I should learn java, I know the basics and once I come across a thing which I have not seen I will look it up and learn it also, I do not have the time to sit for the whole day and learn it, I've got the basics, that's all I need for now until another issue pops up.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  29. Offline

    mcdorli

    1.: Basics aren't enough
    2.: You don't have time learning java, but you have time learning bukkit?
    3.: You can't learb java with bukkit
     
  30. Offline

    andrewginn

    @mcdorli it is for me, I am doing my own way without having to follow the crowd. I can make a plugin come across new things and then research them so I learn it, not learning things and then not using them until another 4 months, this is the way I want to learn, there is nothing wrong in doing that, your just saying from what everyone else saids.
     
Thread Status:
Not open for further replies.

Share This Page