Command Arguments

Discussion in 'Plugin Development' started by toxiccoke, Dec 20, 2015.

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

    toxiccoke

    Hi

    so today i have been working on my core plugin for my network and i have been working on the tokens side of it. started to code the commands but for some reason i can get it to return argument 0 which is /tokens add and that will return test 2 but when i try to add a second argument like /tokens add toxiccoke it should return test 3 but its not its returning test 3 i believe this is a stupid error that i'm not seeing within my code.

    Heres my code:

    Code:
                if(args.length == 0){
                   
                    p.sendMessage(ChatUtils.prefix() + "Invalid args. Usage : /Tokens <Add/Remove> <Player> <Amount>");
                    p.sendMessage("test 1");
                   
                    return true;
                   
                }else{
               
                    if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")){
                   
                        p.sendMessage("test 2");
                        p.sendMessage(ChatUtils.prefix() + "Invalid args. Usage : /Tokens <Add/Remove> <Player> <Amount>");
                       
                        return true;
                   
                        }else{
                   
                            if (args[0].equalsIgnoreCase("add") && args.length == 1){
                           
                                p.sendMessage("test 3");
                           
                        }
                    }
                }
               
               
            }
               
           
            return false;
           
        }
    If anyone could help me that would be great.

    Thanks,

    toxiccoke.
     
  2. Offline

    Lordloss

    Thats because args.length == 1 cant be true if you use more than one argument, you know... ;)
     
  3. Offline

    WolfMage1

    Just a few things (You might remember me from somewhere else, I don't know, if you do Hi again)

    instead of doing
    else {
    if()

    you could do
    else if() {
    }

    second thing

    (I think this might class as spoonfeeding but oh well)

    Code:
     
            if(params.length < 3)
            {
                cs.sendMessage("Computer says nooooooooooooooooooooooo");
                return true;
            }
            switch(params[0].toLowerCase())
            {
                case "add":
                    cs.sendMessage("computer says add");
                    break;
                case "remove":
                    cs.sendMessage("computer says remove");
                    break;
                default:
                    cs.sendMessage("Computer says noooooooX2");
                    break;
            }
    Use dis

    and you might find this useful
    https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
     
Thread Status:
Not open for further replies.

Share This Page