Broadcast Message

Discussion in 'Plugin Development' started by BugsyFTW, Mar 26, 2013.

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

    BugsyFTW

    Hello, i' m trying to make a broadcast message, but the way i' m doing it, seems to complicated and i was wondering if there was a easier way to do this. I' m doing it like this, because i just started coding bukkit 2 days ago, and some help could be appreciated.

    The Code i' m using at the moment:

    Code:
    if(commandLabel.equalsIgnoreCase("sayall")){
                if(args.length == 0){
                    p.sendMessage("" + ChatColor.DARK_RED + ChatColor.BOLD + "Please use the correct format: /sayall <message>");
                }if(args.length == 1){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args[0]);
                }if(args.length == 2){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args[0] + " " + args[1]);
                }if(args.length == 3){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args[0] + " " + args[1] + " " + args[2]);
                }if(args.length == 4){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args[0] + " " + args[1] + " " + args[2] + " " + args[3]);
                }if(args.length == 5){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args[0] + " " + args[1] + " " + args[2] + " " + args[3] + " " + args[4]);
                }if(args.length == 6){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args[0] + " " + args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5]);
                }if(args.length == 7){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args[0] + " " + args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + args[6]);
                }
            }
            return false;

    Thanks
     
  2. Offline

    seemethere

    BugsyFTW
    Couldn't you just do
    Code:
    if (args.length > 0)
        Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD + "[Server] " + args);
     
  3. Offline

    xmarinusx

    BugsyFTW
    You could try +args instead of args[0] args[1] etc. Don't forget to remove the length check of course.

    EDIT: You beat me, seemethere :p
     
  4. Offline

    BugsyFTW

    Ok, now its giving me an eror.

    My current code:

    Code:
    if(commandLabel.equalsIgnoreCase("sayall")){
                if(args.length == 0){
                    p.sendMessage("" + ChatColor.DARK_RED + ChatColor.BOLD + "Please use the correct format: /sayall <message>");
                }if(args.length > 0){
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + args);
                }
            }
            return false;
    help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. Offline

    crushh87

    What error?

    And try this
    Code:
    if(commandLabel.equalsIgnoreCase("sayall")){
                if(args.length == 0){
                    p.sendMessage("" + ChatColor.DARK_RED + ChatColor.BOLD + "Please use the correct format: /sayall <message>");
                }if(args.length > 0){
    StringBuilder sb = new StringBuilder();
                      for (int i = 1; i < args.length; i++){
                      sb.append(args[i]).append(" ");
                      }
                      String allArgs = sb.toString().trim();
                    Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD +  "[Server] " + ChatColor.AQUA + allArgs);
                }
            }
     
  6. Offline

    Croug

    int i would have to equal 0, all arrays start at 0.
     
  7. Offline

    Trevor1134

Thread Status:
Not open for further replies.

Share This Page