Arguments help

Discussion in 'Plugin Development' started by Alex_Cboy, Apr 2, 2014.

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

    Alex_Cboy

    Hello guys, it's not really a problem i have creating a plugin but i was wondering how to get args[0] until i reach args[5] .. like e.x /me hello world blah blah blah..||
    I want to get "hello world blah blah blah"
    anyone that can help with this?
     
  2. Offline

    number1_Master

    I'm a little unsure by what you mean, but are you asking about how to loop through the arguments?

    You could do the following ...

    Code:java
    1. for(int i = 0; i <= 5; i++)
    2. {
    3. args[ i ] // This would be the argument as a String.
    4. // Continue your code.
    5. }


    By the looks of it, do you want to check if an argument is equal to a specific String? You would do it like so:

    Code:java
    1. if(args[0].equals("world")) // and you may continue your code from there.
     
  3. Offline

    user_90854156

    Code:java
    1.  
    2. String msg = ""; //string msg
    3. for (String part : args) { //loops through the arguments of command
    4. if (msg != "") msg += " "; //msg will add spaces
    5. message += part; //puts the arguments in the message string
    6. }
    7.  

    I think this is what you need?
     
  4. Offline

    Alex_Cboy

    number1_Master & MrTang
    Thanks for your help but now i need to get args[1] and all others args[0] = players name that's why.
     
  5. Offline

    number1_Master

    Do not use msg != "", use !(msg.equals(""))

    Also, use a StringBuilder if you're going to continuously add spaces.
     
Thread Status:
Not open for further replies.

Share This Page