getOnlinePlayers doesn't work in 1.7 protocol hack?

Discussion in 'Spigot Plugin Development' started by JordanOsterberg, May 12, 2015.

  1. When using getOnlinePlayers in the 1.7 protocol hack, nothing happens. It seems like the code is skipped, but no idea why.
    Thank you!
  2. I believe for most 1.7 versions, getOnlinePlayers() is deprecated.
  3. It worked for me when I used it.. Is there something in your code preventing it from reaching it?
  4. Nope, the code I used was just
    for (Player p : Bukkit.getOnlinePlayers()){
    // code
  5. What version do you compile against?
  6. I believe 7, possibly 6.
  7. Bukkit version
    • Agree Agree x 1
  8. I thought they meant 1.7.2 and 1.6.4 :facepalm:
  9. Maybe you compile against minecraft 1.8 and the compiler uses the version of getOnlinePlayers() that returns an array.
    Wouldn't that cause a NoSuchMethodException?
  10. Yes.
  11. Then i'm stumped.
  12. Well it works for me, so all that can be assumed is user error. More code would be nice, because it's certainly a problem with the surrounding code, not the #getOnlinePlayers call itself.
    • Like Like x 1
  13. For me I really don't like using deprecated code, so I fastly made my own getOnlinePlayers() Method. If you want, you can use it:

    Code (Text):
    public List<Player> getOnlinePlayers() {
         List<Player> players = new ArrayList<Player>();
         for(World world : Bukkit.getWorlds()) {
              for(Player player : world.getPlayers()) {
         return players;
    I hope I could help you! :)

    ~ Sorry for my english
  14. That's a much, much slower method than using Bukkit#getOnlinePlayers (which OP really isn't having a problem with anyhow)
  15. #getOnlinePlayers is not deprecated, the return value was just changed in the 1.8 update.
    It now returns a Collection by default, but you can still use #toArray()

    and OP,
    • Like Like x 1
  16. Yes you are right :)

    But I thought @TheTrollzJ 's code is not working on the #getOnlinePlayers Methode in the 1.7 protocol hack version of spigot. And with the code snippet I posted it should definitly work fine.
    • Like Like x 1
  17. The problem isn't with #getOnlinePlayers, it's completely different. We just don't have context because more code hasn't been posted.
  18. Well, they did give us code:
    Code (Java):
    for(Player p : Bukkit.getOnlinePlayers()){
    // code
    Maybe he thinks the compiler magically turns //code into whatever he wants!
    • Funny Funny x 1
  19. Make sure you are importing from bukkit and not craftbukkit, this is because CB returns both an array of online players and a collection, which causes a conflict.
  20. There's literally nothing wrong with the posted code. We haven't seen the problem yet.