Broadcast command help.

Discussion in 'Plugin Development' started by zakkinu2, Nov 16, 2013.

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

    zakkinu2

    OK i have this code:
    Code:
                                            String s = "";
                                            for (String ar : args){
                                                s+= ar;
                                            }
                                            Bukkit.broadcastMessage(s);
    that is an example of my code but the command to do that is "/broadcast set <message>" so my problem is whenever i do that command it says "broadcast set" and then whatever i said, I only want it to say everything after "set". any help? This is an example of my code but its the same exact thing kindaof.
     
  2. Offline

    TeeePeee

    Code:java
    1. String output = "";
    2. if(args.length < 1) { return; }
    3. // Go through each argument that isn't the first one (args[0] should equal "set")
    4. for(int word = 1; word < args.length; word++) {
    5. output += args[word] + " "; // Add a word and a space.
    6. }
    7. output = output.trim(); // Get rid of the last space.
    8. Bukkit.broadcastMessage(output); // Broadcast the message


    Should do it.
     
  3. Offline

    zakkinu2

  4. Offline

    Henzz

    zakkinu2
    If you want, you could also use StringUtils static join method.
    Code:
    if (cmdObj.getName().equalsIgnoreCase("broadcast")) {
        if (strings.length > 1) {
            if (strings[0].equalsIgnoreCase("set")) {
                String message = StringUtils.join(strings, ' ', 1, strings.length);
                Bukkit.broadcastMessage(message);
            }
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page