args question

Discussion in 'Plugin Development' started by scorbin60943, Jan 21, 2013.

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

    scorbin60943

    I am making a command with multiple arguments and I am unsure of how to target them.
    I want the command to be like this: Config [configVariable] [setTo this]
    Example: /config Range 3

    The most I have done is target players.
    Please help.
     
  2. Offline

    hockeygoalie5

    Assuming you set up the method the same, the String[] called args is each argument. This is how you get them:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if(cmd.getName().equalsIgnoreCase("config")) {
            String configVariable = args[0]; // First argument
            String setTo = args[1]; // Second argument
        }
    }
    
     
  3. Offline

    camyono

    And dont forget...

    Code:java
    1.  
    2. if ( cmd.getName().... && args.length >= 2 ) { ...
    3.  


    prevent NPE :)
     
  4. Offline

    hockeygoalie5

    Forgot about that, thanks!
     
  5. Offline

    scorbin60943

Thread Status:
Not open for further replies.

Share This Page