Retrieve Numeric value from Command

Discussion in 'Plugin Development' started by dakoslug, May 8, 2012.

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

    dakoslug

    Hi, im trying to make a delayed task.

    Heres an outlook on what I'm trying to do.

    User does command (/ed-downtime x)
    Plugin takes value x (which is seconds)
    variable servertisk = X * 3 = (X*3) L (for the delayed task server ticks)
    My question is how do I get value X using stringargs or any other method?

    In the end the code for the delayed task should look something like this ;

    myPlugin.getServer().getScheduler().scheduleSyncDelayedTask(myPlugin, new Runnable() {
    public void run() {
    //code
    }
    }, servertiskL);
     
  2. Offline

    Double0negative

    Integer.parseInt(x);
     
  3. Offline

    dakoslug

    But how do I parse the value from the command?
     
  4. Offline

    ZachBora

    it's going to be in the args collection
     
  5. Offline

    dakoslug


    So first I would have to get the string value of the cmd used by the user, then parse it
    Integer.parseInt(x);
    ?

    Can you give me the code I would need to use for the string args collection. (still a noob)
     
  6. Offline

    ZachBora

  7. Offline

    dakoslug

  8. Offline

    Double0negative

    yes

    Note that you might want to put a try - catch around it for incase the use puts something other then a number as the argument

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  9. Offline

    dakoslug

    int x;
    try {
    x = Integer.parseInt(args[O]);
    } catch (Exception e) {
    //incorrect
    }
    This correct?
     
  10. Offline

    Double0negative

    yea thats right
     
  11. Offline

    dakoslug


    Thanks! One last question how can I detect that string args even has a value?
     
Thread Status:
Not open for further replies.

Share This Page