Split commands

Discussion in 'Plugin Development' started by djmaster329, Jun 7, 2012.

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

    djmaster329

    Hello,

    I was wondering how I can split a command.

    The command is /verify
    Code:
    But how can I get the [code] from the command?
     
    This is what I have so far:
    [CODE]if(cmd.getName().startsWith("verfy")){
                try {
                    // Create a URL for the desired page
                    URL url = new URL("http://hostname:80/index.html");
     
                    // Read all the text returned by the server
                    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                    String str;
                    while ((str = in.readLine()) != null) {
                    // str is one line of text; readLine() strips the newline character(s)
                    }
                    in.close();
                    } catch (MalformedURLException e) {
                    } catch (IOException e) {
                    }
            }
     
  2. Offline

    Shevchik

    Code:
    public boolean onCommand(CommandSender sender, Command command,
    String commandLabel, String[] args) {
    if commandLabel.equals("verify") {
     
    URL url = new URL("http://hostname:80/index.html");
    return true;}
    }
    
    Sender - player who typed message in chat.
    CommandLabel - command name that you writed in your plugin.yml
    args - Array of words after command.
    Fore example:
    /verify 12sdg42 sdzxv
    verify - commandLabel
    12sdg42 - arg[0]
    sdzxv - arg[1]
     
  3. Offline

    djmaster329

    So, if I want to get the argument from the command, I need
    Code:
    String argument = arg[0];
    ?
     
  4. Offline

    Njol

    This is not correct: commandLabel is the alias which was used (which doesn't even have to be one of the aliases you defined in your plugin.yml as server admins can create new aliases in bukkit.yml). You should thus always use command.getName() and ignore commandLabel.
    Yes, though you should first check whether the user actually typed an argument:
    Code:
    if (args.length == 0) {
        // no argument given
        return false;
    } else {
        String argument = arg[0];
        // your code here
    }
     
  5. Offline

    djmaster329

    Thank you :)
     
Thread Status:
Not open for further replies.

Share This Page