Sending a message to only ops

Discussion in 'Plugin Development' started by Blingdaddy1, Dec 30, 2013.

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

    Blingdaddy1

    I am trying to make a command, so if you do /a, it will send a message to all ops online, but I don't know how to do that. If anyone could help that would be fantastic!
     
  2. Hint: player.isOp() is what you want to use...

    for (Player player : Bukkit.getOnlinePlayers())
    {
    if (player.isOp())
    player.sendMessage("Hello op!")
    }
     
  3. Offline

    Plo124

    Code:java
    1.  
    2. // oncommand thingy
    3. if (cmd.getName().equalsIgnoreCase("ac")){
    4. if (args.length > 0){
    5. String msg = "";
    6. for (int i = 0;i < args.length;i++){
    7. msg += args[i];
    8. }
    9. for (Player p : Bukkit.getOnlinePlayers()){
    10. p.sendMessage(ChatColor.GREEN+"[Op Broadcast] :"+ChatColor.YELLOW+msg);
    11. }
    12. } else {
    13. sender.sendMessage("You need a message");
    14. }
    15. }
    16. [/i]
     
    manuelgu and Wizehh like this.
Thread Status:
Not open for further replies.

Share This Page