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
BugsyFTW Couldn't you just do Code: if (args.length > 0) Bukkit.broadcastMessage("" + ChatColor.AQUA + ChatColor.BOLD + "[Server] " + args);
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
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.
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); } }
This should work ideally http://pastebin.com/KEQH40wH Make sure to keep the ChatColor <BLAH> = chatColor.<BLAH>;