Config question

Discussion in 'Plugin Development' started by dvargas135, Nov 17, 2015.

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

    dvargas135

    So I got my config working
    (example config)
    Code:
    rank1
      commands:
      - say the first rank is {rank} and {player} is in it!
    foobar:
      commands:
      - say {player} is in {rank} rank!
    anything:
      commands:
      - say anything and {player} and {rank} are placeholders
    You can add any string you want if it has the substring (I don't know how else to call it) "commands".

    I made it like this on my code
    Code:
        if (cmd.getName().equalsIgnoreCase("ezb")) {
            if (p != null) {
             if ((args.length > 0) && !(args[0].equalsIgnoreCase("reload"))) {
                   String rank = args[0];
                   String name = args[1];
                   List<String> commandList = getConfig().getStringList(rank + ".commands");
                    for (String command : commandList) {
                         command = command.replace("{player}", name);
                         command = command.replace("{rank}", rank);
                         Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
                         }
    When I do "/ezb foobar dvargas135" it broadcasts: "dvargas135 is in foobar rank!", but when I do something that doesn't exist in the config, such as "foobar123" (taking reference the example code above) it doesn't return anything. My question is how would I make it to show a simple message telling the player that the 'rank' doesn't exist (foobar, rank1, and anything in the config are 'ranks').

    I have tried a null check but that won't work, any ideas?

    Thanks in advance!
     
  2. Offline

    Pr0Pancakeslol

    try to use else
     
  3. Offline

    Zombie_Striker

    @dvargas135
    if(commandlist.size == 0)

    This will test to see if the list has anything in it.
     
  4. Offline

    Scimiguy

    @Zombie_Striker
    You said it backwards. That will check if the list doesn't have anything in it.

    In any case, this is what

    Code:
    if (commandList.isEmpty())
    is for
     
Thread Status:
Not open for further replies.

Share This Page