Solved Broadcast command only sending message to ops

Discussion in 'Plugin Development' started by Techno, Apr 6, 2014.

Thread Status:
Not open for further replies.
  1. As the title says, I have a command /billcast <message>, when the admin / op executes it, it only sends the message to the admins / ops, and not the normal players like I want it to.

    Code (Main.java):
    Code:java
    1.  
    2. public class Main extends JavaPlugin {
    3.  
    4. public void onEnable() {
    5. FileConfiguration config = getConfig();
    6.  
    7. config.addDefault("prefix", "BillCast");
    8. config.options().copyDefaults(true);
    9. saveConfig();
    10.  
    11. }
    12.  
    13. public void onDisable() {
    14.  
    15. }
    16.  
    17. // Main
    18.  
    19. public boolean onCommand(CommandSender sender, Command cmd, String Label, String args[]) {
    20.  
    21. if (cmd.getName().equalsIgnoreCase("billcast")) {
    22. if(sender instanceof Player){
    23.  
    24. if(args.length == 0){
    25.  
    26. sender.sendMessage(ChatColor.RED + "You must have a message to broadcast, silly!");
    27.  
    28. }
    29.  
    30. if(args.length >= 1) {
    31.  
    32. String message = "";
    33. for (String part : args) {
    34. if (message != "") message += " ";
    35. message += part;
    36. }
    37. this.getServer().broadcastMessage(ChatColor.GRAY + "[" + ChatColor.AQUA + getConfig().getString("prefix") + ChatColor.GRAY + "] " + ChatColor.AQUA + message);
    38. }
    39.  
    40. }
    41. return true;
    42. }
    43.  
    44. return false;
    45. }
    46.  
    47. }
    48.  
     
    Jhtzb likes this.
  2. Offline

    Bammerbom

    Techno
    If I am right this would just work.
    but try:
    Code:
    for(Player p : Bukkit.getOnlinePlayers()){
      p.sendMessage(Message to broadcast);
    }
     
  3. Jhtzb
    But its a broadcast plugin, its supposed to send to everyone...
     
    Jhtzb likes this.
  4. Offline

    Bammerbom

    Techno My code will loop through every player and send them a message.
     
  5. Jhtzb
    Ah okay, sorry :)
     
    Jhtzb likes this.
Thread Status:
Not open for further replies.

Share This Page