How to get all online ops on the server

Discussion in 'Plugin Development' started by tyler15555, Mar 11, 2012.

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

    tyler15555

    Hi, I am writing a plugin that whenever a user runs a command with a specific argument, a message is sent to all online ops on the server. What method should I use to get all the online ops?

    Thank you for helping me,

    -Tyler
     
  2. Offline

    LightnessPL

    I think this should be work:

    Code:
    Player[] op = Bukkit.getOnlinePlayers();
    And use this in if bracket
    Code:
    op.isOp()
     
  3. Offline

    7cardcha

    That would get all online players. To get all online ops sort through that array and remove ones that aren't ops. To check if players are ops use Player.isOp()
     
  4. Code:java
    1. for (Player p : Bukkit.getOnlinePlayers()) {
    2. if (p.isOp()) {
    3. p.sendMessage("");
    4. }
    5. }
     
  5. Code:
    List<Player> ops = new ArrayList();
    for(Player p : Bukkit.getOnlinePlayers())
    {
      if(p.isOp())
          ops.add(p);
    }
     
  6. Offline

    Njol

    You can also use
    Bukkit.broadcast(message, Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
    if you really only want to send messages to ops. If you however need the list for ther purposes ignore this post.
    btw: using this method sends the message to the console as well.
     
    AzubuSan likes this.
Thread Status:
Not open for further replies.

Share This Page