Tab Complete

Discussion in 'Plugin Development' started by CreeperFace0777, Jun 4, 2016.

Thread Status:
Not open for further replies.
  1. Hey guys, so I'm making a plugin and my tab complete for the /kit command doesn't work. The one for the /ffa command does though? Any ideas on what's wrong? (Yes the enums have been declared)

    Thanks,

    Show Spoiler
    Code:
    
    public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    
    if (command.getName().equalsIgnoreCase("ffa")) {
    if (args.length == 1) {
    ArrayList<String> cmdArgs = new ArrayList<String>();
    if (!args[0].equals("")) {
    for (commandArgs cmdA : commandArgs.values()) {
    if (cmdA.name().toLowerCase().startsWith(args[0].toLowerCase())) {
    cmdArgs.add(cmdA.name());
    }
    }
    } else {
    for (commandArgs cmdA : commandArgs.values()) {
    cmdArgs.add(cmdA.name());
    }
    }
    Collections.sort(cmdArgs);
    returncmdArgs;
    }
    }
    
    if (command.getName().equalsIgnoreCase("kit")) {
    if (args.length == 1) {
    ArrayList<String> kArgs = new ArrayList<String>();
    if (!args[0].equals("")) {
    for (kitA cmdK : kitA.values()) {
    if (cmdK.name().toLowerCase().startsWith(args[0].toLowerCase())) {
    kArgs.add(cmdK.name());
    }
    
    }
    
    } else {
    
    for (kitA cmdK : kitA.values()) {
    
    kArgs.add(cmdK.name());
    }
    }
    
    Collections.sort(kArgs);
    
    return kArgs;
    
    }
    }
    
    return null;
    }
    
    


    By the way sorry for the formatting, it was cleared when I pasted the code

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    Zombie_Striker

    Code:
    if (!args[0].equals("")) {
    This should not make a difference. If the first arg is blank, checking if a word starts with a empty string will always return true. Remove this if statement and the other else statements.

    Are you sure you encapsulated correctly? Have you debugged?
     
  3. Offline

    Betagear

    Line 20 : Add a space between return and cmdArgs.

    Instead of if (!args[0].equals("")) { use if(!args.isEmpty()){
     
Thread Status:
Not open for further replies.

Share This Page