Bukkit.getServer().getOnlinePlayers()

Discussion in 'Plugin Development' started by JBoss925, Jul 18, 2014.

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

    JBoss925

    Hello, I'm trying to loop through players on a server so I can send them a packet. Here's my code:
    Code:java
    1. for(Player p: Bukkit.getServer().getOnlinePlayers()){
    2. try {
    3. pe.sendToPlayer(p, location, 0f, 0f, 0f, 1f, 1);
    4. } catch (Exception e) {
    5. e.printStackTrace();
    6. }
    7. }

    Though, I don't think my code is the problem, I get an error on "getOnlinePlayers()" and here's what the error is, "
    Ambiguous method call. Both
    getOnlinePlayers () in Server and
    getOnlinePlayers () in Server match.
    "
     
  2. Offline

    1Rogue

    Make sure you are using the appropriate versions for all your dependencies. This sounds like a mismatch between implementing craftbukkit and bukkit.
     
  3. Offline

    JBoss925

    I'm only implementing the latest version of craftbukkit and the latest version of Protocol Lib. I'll play around with some stuff.

    Well, I figured out why it's an ambiguous method call, there are 2 getOnlinePlayers() methods.
    Collection and Array Methods (open)


    I don't know a way around it, I tried to define it as a Collection<Player> and I can't seem to work it out.

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

    1Rogue


    You could either retrieve the value beforehand and store it in a variable, or stop implementing craftbukkit and just use Bukkit.
     
  5. Offline

    JBoss925

    I need craftbukkit for the added features. I tried defining the variable as a Collection<Player> as said before but my IDE doesn't return the correct method. I'm trying to get the correct getOnlinePlayers() but it only returns the Player[] method. I'll try to mess around with imports.
     
  6. Offline

    Gater12

    JBoss925
    Add bukkit and craftbukkit. Make bukkit a higher priority than craftbukkit.
     
  7. Offline

    JBoss925

    Ok, thanks.
     
  8. Offline

    RingOfStorms

    Also for future reference, you can ignore ambiguous errors in your IDE and it will still compile just fine. But it is better to make the bukkit api a higher priority.
     
Thread Status:
Not open for further replies.

Share This Page