Deprecated Bukkit.getOnlinePlayer()

Discussion in 'Spigot Plugin Help' started by Terrick, May 28, 2015.

  1. Relatively new to coding in itself, and I've run into an error, fixing up an old plugin my friend sent me and I ran into one final error.
    The build was from way back in 1.5.1, but it's the first time I've seen the error.

    Here's what it looks like

    Don't know what to do, any help?

    Along with these being deprecated as well, still don't know a fix.
  2. If something is deprecated but still works, just use it. However, don't expect it to work on later builds.
  3. The build of bukkit/craftbukkit/spigot you're using for that plugin is way out of date. If your server is running on 1.8+, you should grab an updated server file from BuildTools and change the dependency to fix the deprecation warning, because that method no longer exists.
  4. I don't really know what to look for to fit it in that code, it's a 1.5 build but the plugin worked up until 1.8.

    I can't build the plugin without fixing those errors, sadly.
  5. The way to do it would be to do this:
    Code (Java):
    // Replace the first two lines in the first file with these:
    Collection<? extends Player> players = Bukkit.getOnlinePlayers();
    for (int i = 0; i < players.size(); i++) {
        // rest goes here
    The getScore method pulls in custom names. Not sure what you're doing there so I can't help with that bit.
  6. The first file?
    I don't quite understand.
  7. Use a collection instead of Player[] and just iterate through it:

    for(Player player : players)

    • Agree Agree x 1
  8. Don't use Bukkit.getOnlinePlayers() try to use getServer().getOnlinePlayers()
  9. Doesn't work.

    Player[] tempCopy = Bukkit.getOnlinePlayers();

    That's what I have currently, and it's underlining the () and telling me it's an ambiguous call.
    #9 Terrick, Jun 11, 2015
    Last edited: Jun 11, 2015
  10. @Terrick - Have you tried this?

    Code (Text):

    for (Player p : Bukkit.getServer().getOnlinePlayers()) {
      // if (p.getG <- That's all I can see in the screenshot lol
    • Like Like x 1