Using command arguements

Discussion in 'Resources' started by tharvoil, Aug 21, 2011.

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

    tharvoil

    I'm semi-new to java(took a semister class @ college), as well as new to plugin development. How do I pass a command arguement to a method.

    e.g. I have with onCommand - if(cmd.getName().equalsIgnoreCase("refer")) and I want to pass on a player name typed after the refer( /refer <name>, I need the <name>)
     
  2. Offline

    stelar7

    /refer args[0] args[1] args[2]
    and so on..

    so the first after the command is:
    args[0]

    this prints out the first thing you wrote after /refer


    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (commandLabel.equalsIgnoreCase("refer")) {
            if (args.length == 1) {
                sender.sendMessage(args[0]);
                return true;
            } else {
                sender.sendMessage("Invalid arguments!");
            }
        }
        return false;
    }
    
     
  3. Offline

    tharvoil

    thanks, that makes life so much easier than what I was trying.
     
Thread Status:
Not open for further replies.

Share This Page