Bukkit.getOnlinePlayers() does now return Collection<? extends Player>

Discussion in 'Plugin Development' started by Bammerbom, Jul 16, 2014.

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

    Bammerbom

    Hello bukkit developers!

    It looks like since the 1.7.10 build Bukkit.getOnlinePlayers() now returns an Collection<? extends Player>, I know how to update my code, but wont this break almost 70% of the existing plugins?
    I couldnt find more information about this change, so I created this topic.

    Does anyone has more information about this change?
    And update my code to make my code 1.7.10 compitable or leave my code as it is to make it 1.7.9 compitable?

    Picture of this change: http://grab.by/yCh6

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    aaomidi

    The old getOnlinePlayers still exists but is deprecated, it will give time for devs to update their code.
    http://jd.bukkit.org/dev/apidocs/org/bukkit/Server.html
     
  3. Offline

    Bammerbom

    aaomidi
    How can I acces this method, because anytime I do this it automaticly returns a Collection
     
  4. Offline

    TheMcScavenger

    Not sure if 1.7.9 and 1.7.10 are compatible; haven't tested it yet. Just make two versions of the plugins, you'll have to update it some time.. It's also a really easy fix (the Bukkit.getOnlinePlayers):

    Code:
    List<Player> onlinePlayers = new ArrayList<Player>();
    for(Player p : Bukkit.getOnlinePlayers()){
        onlinePlayers.add(p);
    }
     
  5. Offline

    aaomidi

    I linked you to the javadocs Bammerbom, Its not that hard to figure it out from there.
     
  6. Offline

    TheMcScavenger

    Code:java
    1. Bukkit._INVALID_getOnlinePlayers()


    It's also not difficult to just tell him.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  7. Offline

    aaomidi

    Why make a static call and reconstruct a new list when the method already provides you with a collection...?

    Read my signature.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  8. Bammerbom Where do your get your information of almost 70% anyway?

    But in any case, if your plugin is compiled against an older version of Bukkit, it will still use the older version of the method, and therefore supports both the older CraftBukkit and the latest CraftBukkit. If you compile against a newer version of Bukkit, it will only use the newer method, meaning it won't support older versions of CraftBukkit.

    Net result: Build against the older version if you want to support older version of CraftBukkit, and let the magic performed by the Bukkit team handle the rest.

    TheMcScavenger I don't see what your fix does and doesn't really seem to fix anything.
     
  9. Offline

    TheMcScavenger

    You don't have one on my screen ;)

    Actually, if you need it as a list, instead of a collection, this does fix it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  10. TheMcScavenger A List is a Collection.

    Edit TheMcScavenger: On second thoughts, your post is irrelevant to this change if it's just that you need it as a List rather than a Collection - the old method didn't return a List.
     
  11. Offline

    aaomidi

  12. Offline

    xize

    Well I have made a modified version of the snippet who ShadyPotato had posted to get a idea.

    Normally I shouldn't spoonfeed directly code but hence I hate it when things aren't compat even when it is just only for the justify for how things are writed/conventions what could have made this change which is for me not to acceptable for me.

    https://github.com/xize/manco2/blob/master/src/tv/mineinthebox/manco/ManCo.java#L302 orginal link is there to.
     
  13. xize Ah yes, the code that Wolvereness openly criticised that it needn't exist? :p

    If you want to support older versions, build against older versions.
     
  14. Offline

    Bammerbom

    TheMcScavenger
    Another question: Why is the EntityDamageEvent constructor (Player, DamageCause, Double) deprecated?
     
  15. Bammerbom I would assume it's preferred to use the more specific events (i.e. by block or by entity)
     
  16. Offline

    Bammerbom

    AdamQpzm
    the EntityDamageByBlockEvent and EntityDamageByEntityEvent constructors are deprecated too
     
  17. Offline

    Rocoty

    Bammerbom If you had just read the documentation you'd know by now that they are deprecated in favour of a new, more specific constructor.

    Why does nobody read the docs?
     
  18. Offline

    Traks

    Because the damage is now calculated using modifiers and modifier functions. I believe this was added to make more room for customisation. Using the old constructors in which the final damage value was specified would contradict these changes.
     
  19. Offline

    xize

    AdamQpzm

    hmm I wonder how that works, because all my plugins which used the array Player[] didn't work on the newer version when compiling against a older version, but if I would do Collection and compile against the new version it wouldn't work vice versa on older versions because it does sort of hardcode it into the compilation runtime and still throws a NoSuchMethodException:p

    -edit-

    compiling against a old version works, no reflection needed, don't know why I failed with my first test but I was probably blind, tested it again and no errors.
     
  20. Offline

    Necrodoom

    I haven't seen a plugin compiled with bukkit using old getonlineplayers error on a bukkit server with new one.
     
  21. Offline

    Bammerbom

    Rocoty Traks xize Necrodoom
    How can I now make my EntityDamageEvent constructors, or just Ignore the warnings?
    I couldnt find a new constructor in the JavaDocs.
     
  22. Offline

    Necrodoom

    Bammerbom it is listed right there..
    The constructor you tried will only show up deprecated if you used a devbuild, in which case it would show a third constructor.
     
Thread Status:
Not open for further replies.

Share This Page