Ok, so I'm messing around with arguments and stuff, and I wanted to make a broadcast plugin. Desired effect: /tellall Hey guys! -> [Server]Hey guys! Now, in the code, my String "message" has to be all the arguments except 0. How can I fix this? Code: Code: import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class Broadcast extends JavaPlugin { public boolean onCommand(CommandSender sender, Command command, String label, String[] args){ if(label.equalsIgnoreCase("tellall")){ Player player = (Player) sender; if(player.hasPermission(Broadcast.tell)){ if(args.length == 0){ player.sendMessage(ChatColor.RED + "Usage: /tellall <message>"); }else{ String message = args[1]; Bukkit.broadcastMessage(message); } } return true; } return false; } }
Rufus5 Loop through all args. Append them and a space to a StringBuilder. Invoke toString followed by trim (to get rid of the last space) to StringBuilder and broadcast that.
Rufus5 Use a for statement to loop through the arguments, starting from the desired index, and append to a StringBuilder.
Rufus5 For your example you can actually just use all arguments.. As 'tellall' is the command(label) and the args starts with 'Hey' (so args[0] = Hey) To get the args into a nice message follow Gater12
Rufus5 Like Flamedek said, args do not include the command label. Code:java String message = "[Server] " + StringUtils.join(args, " "); Bukkit.broadcastMessage(message); Your permissions check also needs to be a string - "Broadcast.tellall"