Multiple Command Args

Discussion in 'Plugin Development' started by MrConnn, Mar 9, 2015.

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

    MrConnn

    I recently got a hold of a tokens api and I've been messing with it. I'm trying to run it off one command as it didnt really work using /tokens and /tokens give seperate. So I decided to turn to Bukkit (as usual). I've got it so if args = 0 send them their balance of tokens. I want to try it to they can do /tokens give <name> <amount> but I'm not sure how it'd come along. Anyone?
     
  2. Online

    timtower Administrator Administrator Moderator

    @MrConnn If args>0, check first argument, if args>2 check for the name and amount.
     
  3. Offline

    MrConnn

    @timtower Could you possibly show an example. It's complicated explaining stuff to me w/ out a screenie xD
     
  4. @MrConnn
    Code:
    if(args.length == 3) {
        // tokens give <name> <amount>
    }
     
  5. Offline

    MrConnn

    @DaChiimp I checked if the args lenght is equal to 3. I then checked if the args[0] of that was "add" then then arg[1] was the target but I'm not sure what to set the last arg which is the amount.
     
  6. Offline

    mythbusterma

    @MrConnn

    Integer.parseInt(String) ?
     
  7. @MrConnn As @mythbusterma said you need to try parse the string to an integer. This is done by Integer.parseInt(args[2]); and it will throw a NumberFormatException if it is a string and not a integer.
     
Thread Status:
Not open for further replies.

Share This Page