Boolean isPlayerConnected()?

Discussion in 'Spigot Plugin Development' started by MrThunder_, Jul 13, 2015.

  1. Hey guys,

    I am trying to get some values of the PlayerList of BungeeCord, but the problem is, I have to set the method to wait before the execution can complete. But I am just curious how would I do achieve this?

    I was wondering, what would be the best way to do it? Btw, I'm coding on the Bukkit side, not BungeeCord.
    Because what I have now doesn't work. I'm stuck.
  2. If you just want to run some code later use the BukkitScheduler and a delayed task. (Remember avg 20ticks/sec when scheduling the task).
  3. I prefer Java's ExecutorService because the BukkitScheduler can be inaccurate.
  4. The bulkit scheduler is "inaccurate" if the server is lagging and the ticks take longer than they should to execute. But using an ExecutorService leads to thread safety issues that you have to be careful of. You shouldnt access anything in the spigot api on any thread that is not the main one.
  5. Yes, but with Bukkit schedulers you have the same problem.
  6. Yeah, I got it.
    Hell yeah, more problems. What is the solution?
  7. And the bukkit scheduler doesn't have those exact same thread safety issues?

    Using an ExecutorService (preferably a single-threaded one for locking) you can simply just have the thread wait until the desired state is available. Though your question is a bit odd, if Bukkit#getPlayer returns null or OfflinePlayer#isOnline is false, you've essentially answered the title's question.
  8. Mmh yeah. One more thing, if Bukkit#getPlayer returns null, you still can't say that the player is not connected to the network. Only that the player was not online on the specific server that was tested on.
  9. Yes, same applies for #isOnline