Solved Issue with Bukkit.broadcast

Discussion in 'Plugin Development' started by Rmarmorstein, Apr 24, 2013.

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

    Rmarmorstein

    I am having an issue with bukkit.broadcast, I am trying to use it to make staff members get a message from a staff chat.

    This is working, and it is just checking if the sender has the permission. http://pastebin.com/aw47H56r

    and this one is not, where it uses the Bukkit.broadcast http://pastebin.com/7yjrLFN0

    Is there anyway around this? When i was using something like this...

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sndr, Command cmd, String label, String[] args) {
    3. if(label.equalsIgnoreCase("sc")) {
    4. if(!(sndr instanceof Player)) {
    5. return false;
    6. }
    7. if (args.length == 0) {
    8. return false;
    9. } else {
    10. String perm = "StaffChatX.chat";
    11.  
    12. String msg = StringUtils.join(args, " ");
    13.  
    14. for(Player p : Bukkit.getServer().getOnlinePlayers()) {
    15. if (p.hasPermission(perm)) {
    16. p.sendMessage(msg);
    17. return true;
    18. }
    19. }
    20.  
    21. }
    22. }
    23. return false;
    24. }
    25.  


    The other people can send messages, but only I see them..

    Anyone have suggestions?
     
  2. Offline

    Rocoty

    You are returning the method in the for-loop, thus stopping the entire execution for that method, breaking the loop. That's why it only iterates once, and stops. move "return true;" to after the loop.
     
  3. bukkit.broadcast should work, but I heard that pex breaks the system, so a question, with what permissions plugin are you testing?
     
  4. Offline

    stuntguy3000

    Pex doesn't break anything, use

    bukkit.broadcastmessage("message here");
     
  5. Offline

    Rprrr

    ferrybig likes this.
  6. Offline

    Rocoty

    Well, OP almost had the right idea. Their only issue is that they are breaking execution after the loop's first iteration. Thus, the message only gets to the first recipent.
     
Thread Status:
Not open for further replies.

Share This Page