Solved Broadcast Issue

Discussion in 'Plugin Development' started by Jason Malouin, Jun 7, 2015.

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

    Jason Malouin

    Okay, So I want to have a permission to allow someone to broadcast a message to the server (message already set in config) But I dont know what to do If I dont want someone to be able to use the command , but still be able to see the message. Heres my code

    Section Of Code I Need Help With
    Code:
    else if(args[0].equalsIgnoreCase("broadcast")){
                    if(player.hasPermission("donate.mod")){
                    Bukkit.broadcastMessage(ChatColor.GREEN + "[" + this.getConfig().getString("Prefix") + "] " + ChatColor.GOLD + ChatColor.GOLD + this.getConfig().getString("Broadcast", "donate.broadcast"));
                    player.sendMessage(ChatColor.DARK_RED +"Broadcast Successful");
                    }else{
                        player.sendMessage(ChatColor.DARK_RED + "You Have Insufficient Permissions To Perform This Command!");
                }
        }
    
    Thanks Guys, I Really Apprecite Your Help
     
  2. Offline

    Ricecutter0

    If you set the permission in the second argurment in the method...

    Code:java
    1. Bukkit.broadcast(MESSAGE, PERMISSION);


    Then anyone with that permission node will be able to view the message, but if they don't have the set permission node (in your case you've set it to "donate.mod"), they can't perform the command.

    I'd suggest try using this code:

    Code:java
    1. else if (args[0].equalsIgnoreCase("broadcast")) {
    2. if(!sender.hasPermission("donate.mod")){//if they don't have permission...
    3. sender.sendMessage(ChatColor.DARK_RED + "You have insufficient permissions to perform this command!");
    4. return true;
    5. }
    6. Bukkit.broadcast("INSERT MESSAGE HERE", "INSERT PERMISSION HERE");//if they do.
    7. sender.sendMessage(ChatColor.GREEN + "Broadcast successful!");
    8. }
     
    Last edited: Jun 7, 2015
  3. Offline

    Jason Malouin

    If you scroll over on the Bukkit.broadcast, You can see at the end of my Config line , Ive placed a seperate permission for this, But it does not work, Is this permission set in the correct spot ?

    Code:
    Bukkit.broadcastMessage(ChatColor.GREEN + "[" + this.getConfig().getString("Prefix") + "] " + ChatColor.GOLD + ChatColor.GOLD + this.getConfig().getString("Broadcast", "donate.broadcast"));
    
    At the end , you see "Donate.broadcast"
     
  4. @Jason Malouin And? That's what your code does. If you meant to make that the permission, then you need to do a comma not a plus. (, not +)
     
  5. Offline

    Ricecutter0

    In your code, you're using...
    Code:java
    1. Bukkit.broadcastMESSAGE[...]


    You should be using just broadcast...

    ex:
    Code:java
    1. Bukkit.broadcast(message, permission);


    See my previous post, I edited it to make more sense.
     
  6. Offline

    Jason Malouin

    Okay Thanks

    Code:
                Bukkit.broadcast(ChatColor.GREEN + "[" + this.getConfig().getString("Prefix") + "] " + ChatColor.GOLD + ChatColor.GOLD + this.getConfig().getString("Broadcast"), "donate.broadcast");
    
    I'm Assuming That Would Be Better The Permission Being At The End
     
  7. Offline

    Ricecutter0

    @Jason Malouin

    Actually, the method calls for the permission to be at the end, but yes, you're now correct.

    And if you're satisfied, please mark this thread as Solved. :D
     
  8. Offline

    Jason Malouin

    I was just asking, If My changes would fix the issue
     
  9. @Jason Malouin If you want to send the message to everyone, use broadcastMessage(String) instead.
     
    Googlelover1234 likes this.
  10. Offline

    Ricecutter0

    If you're code matches either one of these, yes you're code should work just fine now.

    Yes but he's trying to add a permission to it, so I suggested using the method:

    Code:java
    1. Bukkit.broadcast([...]);


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page