getServer().getOnlinePlayers() with a static function?

Discussion in 'Plugin Development' started by Zettelkasten, Jul 20, 2012.

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

    Zettelkasten

    Hey guys!

    I got a problem with my plugin. My goal is that my PlayerListener (onPlayerJoin) is able to get all the online players in a Playerarray.
    The problem is: I cannot use "MyPlugin.getServer().getOnlinePlayers()" in "onPlayerJoin(..)".
    But how shall I get it then?
    Would be wonderful if you know an answer.. (sitting now 2 hours on this :()

    Thank you for help,

    Zettelkasten
     
  2. Bukkit.getServer().getOnlinePlayers()
    mayby is that the solution, the next time, look at the javadocs, dont forget to import it
     
    Zettelkasten likes this.
  3. Offline

    Zettelkasten

    Thank you for helping me n00b :)

    JavaDocs looks pretty cool - will use this the next time when I have such a problem!
     
  4. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Your player join monitoring method should not be static. In fact, if you're so new to java that you don't know how to access non-static elements within a static method you really shouldn't be doing anything static yet ;)
     
  5. Offline

    Zettelkasten

    Okay, I see. But why does it count as an error in Eqlipse when I just do MyPlugin.getServer().getOnlinePlayers()?
     
  6. Offline

    Darksonn

    Because getServer() is'nt static in MyPlugin, you need an instance of MyPlugin in a variable to use that method. (It is static on Bukkit.getServer())
     
    Zettelkasten likes this.
Thread Status:
Not open for further replies.

Share This Page