How do you broadcast more than one word? ( Without a lot of effort)

Discussion in 'Plugin Development' started by shadrxninga, Apr 24, 2011.

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

    shadrxninga

    I have a problem. I made a plugin that broadcasts a msg using /broadcast <msg> but at the moment it can only broadcast one word.

    I was wondering if there is an easier way to broadcast more than one word without having to do this.

    Code:
    String p = args[0] + "" + args[1] + " " + args [2] etc etc;

    Here is all of the code

    Code:
     public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
            // both commands need a player to be the sender to get the location!
            Player player = (Player)sender;
            // OP version
            //if (!player.isOp()) return true;
    
            if (command.getName().equalsIgnoreCase("broadcast")) {
                if (args.length>=1) {
                    String p = args[0] + "" + args[1];
                    getServer().broadcastMessage(ChatColor.RED + "[" + ChatColor.GOLD + "Broadcast" + ChatColor.RED + "]" + ChatColor.AQUA +  " " + p);
                    return true;
                }else
                    player.sendMessage(ChatColor.GREEN + "Enter a Message");
            }
    Thanks
     
  2. Offline

    Trucaur

    Use a loop.
    For example :
    Code:
                String text = "";
                for (String str : args) {
                    text += " "+str;
                }
                getServer().broadcastMessage(text)
    
     
  3. Offline

    Archelaus

    Code:
    args.toString()
     
  4. Offline

    Xaw4

    i'm sry to say that, but
    wouldn do that...

    i'd say something like that
    Code:
    String commandostring="";
    for (String string : args) {
                 commandostring+=string+" ";
    }
     plugin.getServer().broadcastMessage(commandostring);
    but i think its still a workaround

    EDIT: Sry, didn't see Trucaur's Post ;)
     
  5. Offline

    shadrxninga

    thanks for the help. I got it working.
     
Thread Status:
Not open for further replies.

Share This Page