Get all players (v1.11+)

Discussion in 'Plugin Development' started by Plx0wn, Dec 31, 2016.

Thread Status:
Not open for further replies.
  1. Hi there! I want take all players name with

    Code:
    for (Player player : Bukkit.getOnlinePlayers()) {}
    I have an error, and I don't undestand it... I think my code is correct!

    Exception (open)

    Code:
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.tabComplete(CraftServer.java:1596) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.MinecraftServer.tabCompleteCommand(MinecraftServer.java:1112) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:2133) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.PacketPlayInTabComplete.a(SourceFile:52) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.PacketPlayInTabComplete.a(SourceFile:11) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
    Caused by: java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()[Lorg/bukkit/entity/Player;
            at fr.plx0wn.TagListener.onTab(TagListener.java:196) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_73]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-50acb44]
            ... 17 more


    Thanks for your answers!
     
  2. Offline

    ShaneCraftDev

    What is on line 196 in fx.plx0wn.TagListener ?
     
  3. Offline

    oriamrm

    As @ShaneCraftDev Said, we need to know what's on line 196.
    Anyway, if it's that:
    Code:
    for (Player player : Bukkit.getOnlinePlayers()) {}
    
    Then Try Instead:
    Code:
    List<Player> players = new ArrayList<Player>(Bukkit.getOnlinePlayers());
            for(Player player : players){
                //Do Your Stuff
            }
     
  4. @Plx0wn
    Although @oriamrm's method is an alternative way of doing it, it won't work in this case.

    The problem here is that your code is looking for Bukkit.getOnlinePlayers() to return an array of Players, which it doesn't in newer versions, it returns a Collection of players. The most likely cause of your code looking for an array is that you are using an old jar as a dependency in your project. Update this jar you're building against to the latest version and everything should work.
     
    timtower likes this.
Thread Status:
Not open for further replies.

Share This Page