Broadcast to all operators.

Discussion in 'Plugin Development' started by mrdude123, Mar 22, 2015.

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

    mrdude123

    Code:
       
            if(player.isOp()); {
                player.sendMessage(ChatColor.RED + ("Hey, ") + sender.getName() + (" needs a kit!"));
            }
                
    player.sendMessage sends a message to the person who executed the command. That's not what I want. I want a message to go through only to operators. Any ideas?
     
  2. Offline

    teej107

    @mrdude123 Loop through the online players, check to see if they are OP, and send the message if they are.
     
  3. Offline

    mrdude123

    @teej107 Example? I'm not catching your drift.

    @teej107
    Code:
            player.isOnline();
            if(player.isOp()); {
                player.sendMessage(ChatColor.RED + ("Hey, ") + sender.getName() + (" needs a kit!"));
    
    
    How's this?

    {{Posts merged by Myrathi}}
     
    Last edited by a moderator: Mar 22, 2015
  4. Offline

    teej107

  5. Offline

    mrdude123

  6. Offline

    rcth

    There are two methods:
    Code:java
    1. Bukkit.broadcastMessage(java.lang.String message) ;

    And:
    Code:java
    1. Bukkit.broadcast(java.lang.String message, java.lang.String permission);


    Use the second method. For 'permission', you could use "yourplugin.operator" if all OPs have the same rank.

    Other method would be this:
    Code:java
    1.  
    2. for (Player p : Bukkit.getOnlinePlayers()) {
    3. if (p.isOp()) {
    4. p.sendMessage("Your text");
    5. }
    6. }
    7.  
     
  7. @rcth Please don't spoonfeed!
    You don't need java.lang.String. Just String works too because it is imported by default
     
  8. Offline

    rcth

    Just quoting the Bukkit Javadocs. Calm down.
     
  9. Invisible

    nverdier

    @rcth I'm sure none of that is copy and pasted from the JavaDocs...
     
  10. Offline

    teej107

    Last edited: Mar 23, 2015
  11. Invisible

    nverdier

    @teej107 And where is that?
     
  12. Offline

    teej107

    @nverdier
    Said in that order so I thought you were referring to the methods he suggested from the JavaDocs.
     
  13. Invisible

    nverdier

    @teej107 I see. Should've made it more clear. I apologize.

    @mrdude123 Below is how I would do it. I know there are many different way's.

    Code:
    Bukkit.broadcast("Message", "perm.node");
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
    teej107 likes this.
Thread Status:
Not open for further replies.

Share This Page