Checking if user has sent wrong arguments

Discussion in 'Spigot Plugin Development' started by Buby, May 14, 2016.

  1. Hey guys! I was messing around with commands and I have run over a bug that I cant really get past.. I think I am just not doing it right.. someone help.
    Code (Text):

    switch(args[1]){
                                    case "add":
                                        if(!(args[2] == null)){
                                           
                                        if(config.getList("BlackListed_Worlds").contains(args[2])){
                                            sendMessage(player, "alreadyadded", "");
                                        }else{
                                            ArrayList<String> list = (ArrayList<String>) config.getStringList("BlackListed_Worlds");
                                            list.add(args[2]);
                                            this.getConfig().set("BlackListed_Worlds", list);
                                            saveConfig();
                                                sendMessage(player, "addedworld", args[2]);
                                            }
                                        }else{
                                            sendMessage(player, "blacklistusage", "");
                                        }
                                    break;
     
    sendMessage is my method.
    But for the first if statement, I am seeing if there is no argument for the 3rd argument. I am not sure if I am doing it correctly. am I suposed to do
    Code (Text):

    if(args[2] !=null){
    }
     
    ?
     
  2. No just check the length of the string array.
     
    • Like Like x 1