Solved PlayerQuitEvent and getOnlinePlayers

Discussion in 'Plugin Development' started by br456, Apr 11, 2014.

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

    br456

    After a playerQuitEvent is called, I check the online players. The player that just quit is in the arraylist, how do I fix this?
     
  2. Offline

    Twisted_Panda

    What: remove them from the arraylist when they leave?
     
  3. Offline

    br456

  4. Offline

    Twisted_Panda

    The reason the player that quit is still in the arraylist, is because you never removed him..
     
  5. Offline

    br456

    Twisted_Panda
    Isn't this controlled by bukkit, it is a method from the bukkit API
     
  6. Offline

    leet4044

    br456 ArrayList aren't controlled by Bukkit? just remove them from the list when they leave.
     
  7. Offline

    br456

    leet4044
    I get the online players by using

    Bukkit.getServer().getOnlinePlayers();
     
  8. Offline

    Twisted_Panda

    Be more clear <_>: List threw all players online and check if they're on the list.
     
  9. Offline

    Niknea

    br456 Please read up more about Java and Bukkit. Array Lists are from Java, not Bukkit, therefore Bukkit doesn't "control" them.
     
  10. Offline

    br456

    Niknea
    By saying "controlled by bukkit", I meant the arraylist that is returned by the method Bukkit.getServer().getOnlinePlayers();
     
  11. Offline

    Niknea

    br456 What? How can an ArrayList just magically return after a method implemented from Bukkit, not Java. If you want to check the online players and see if there in the array list, then do this, create an enhanced loop, and check if there in the array list.
     
  12. Offline

    Go Hard

    What are you exactly trying to do?
     
  13. Offline

    xTrollxDudex

    Go Hard
    Read OP again

    br456
    Event is called before player actually leaves the server. He will be visually removed, BUT not yet removed from memory on the server. Adding a small delay should fix this
     
    Konkz likes this.
  14. Offline

    coasterman10

    Bukkit.getOnlinePlayers() is NOT an ArrayList, it's an array. When you are checking the online players, for whatever task you're doing, just ignore that player with an if statement or other conditional. Or just schedule a task to run the next tick.
     
  15. Offline

    Quackster

    Try adding a small delay check after PlayerQuitEvent.

    Code:
    Bukkit.getServer().getScheduler().runTaskLater(plugin, new Runnable()
    {
    public void run()
    {
    // code here
    }
    }, 0L);
    Where 0L is the server ticks, 20 ticks is the equivalent to one second.
     
  16. Offline

    br456

    Quackster and Konkz like this.
Thread Status:
Not open for further replies.

Share This Page