Solved Issue with Bukkit.broadcast

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

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


    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.

    and this one is not, where it uses the Bukkit.broadcast

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

    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 = "";
    12. String msg = StringUtils.join(args, " ");
    14. for(Player p : Bukkit.getServer().getOnlinePlayers()) {
    15. if (p.hasPermission(perm)) {
    16. p.sendMessage(msg);
    17. return true;
    18. }
    19. }
    21. }
    22. }
    23. return false;
    24. }

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

    Anyone have suggestions?
  2. Offline


    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. Offline


    bukkit.broadcast should work, but I heard that pex breaks the system, so a question, with what permissions plugin are you testing?
  4. Offline


    Pex doesn't break anything, use

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


    ferrybig likes this.
  6. Offline


    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