Checking an Argument

Discussion in 'Plugin Development' started by diamondcodes, Nov 20, 2014.

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

    diamondcodes

    How can I check if the third argument of a command is a integer? (/Test Test Int) And how would I get that Integer? Thanks
     
  2. Offline

    JordyPwner

    Use args


    if (args.length == 0) {
    //do something
    }else if(args.length == 1{
    if (args[0].equalsIgnoreCase("test")) {
    //do some
    }
    }
    }
     
  3. Offline

    teej107

  4. Offline

    FabeGabeMC

    diamondcodes
    Arrays and the length act differently. Arrays ([]) use the 0-(size of array), but the length actually shows how many of them there are (Example: /<0> <1> <2> <3> (Size is 3, but to get the 3rd arg, use args[2])).
    Also, to get an int, use Integer.parseInt(String) as teej107 said.
     
  5. Offline

    mine-care

    To turn a string to int, use Integer.parseInt(string) its a good idea to handle a possible exception, that occurs when the string is not number but contains other characters as well.
     
  6. Offline

    Totom3

    Actually the command name is not counted as an argument, it would be : /cmd <o> <1> <2>. Therefore the integer diamondcodes is looking for is the 2nd argument, or args[1].
     
  7. Offline

    TheOatBaron

  8. Offline

    FabeGabeMC

    Totom3
    What I meant is what length he should be using for each case.
     
Thread Status:
Not open for further replies.

Share This Page