Solved How to get everything after the command label

Discussion in 'Plugin Development' started by com. BOY, May 18, 2014.

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

    com. BOY

    How to get everything after the command label? I have a broadcast command and need to get everything after the label. For example, when someone types:
    Code:
    /broadcast Hello, hello, testing testing!! :)
    I need to get the string
    Code:
    Hello, hello, testing, testing!! :)
    It seems simple but I can't seem to find a way. I have tried iterating through all the arguments and adding them to a StringBuilder with a space in between, but for some reason it cuts off at !'s.
     
  2. Offline

    es359

    Could you post your code?
     
  3. Offline

    com. BOY

    Hey, now it suddenly works after rewriting :/ Probably made some stupid mistake. Sorry!

    Code:java
    1. StringBuilder builder = new StringBuilder();
    2.  
    3. for (String s : args)
    4. builder.append(s).append(' ');
    5.  
    6. String message = builder.toString().trim();
     
  4. That does make sense. If you want more customizability, I would recommend using this:
    Code:
    int startingIndex = 0; // You can change this to 1 if the first argument for the command is not a message, etc.
    String separator = " "; // You can change this to for example, ", " if you want the text as a list.
    for (int i = startingIndex; i < args.length; i++) {
        if (i == args.length - 1) builder.append(args[i]);
        else builder.append(args[i]).append(separator);
    }
    
     
    es359 likes this.
Thread Status:
Not open for further replies.

Share This Page