setTabCompleter can't handle multi-word arguments.

Discussion in 'Plugin Development' started by DePianoman, Feb 28, 2019.

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

    DePianoman

    I have a TabCompleteListener class that waits for the player to Tab Complete the join command:

    Code:
    public class TabCompleteListener implements TabCompleter {
    
        public Main plugin = Main.getInstance();
    
        @Override
        public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args){
    
            if(cmd.getName().equalsIgnoreCase("join")){
                if(sender instanceof Player){
                    File dir = new File(plugin.getDataFolder()+File.separator+"courses");
                    File[] dirListing = dir.listFiles();
                    List<String> worlds = new ArrayList<>();
                    if(dirListing != null){
                        for(File f : dirListing){
                            FileConfiguration course = YamlConfiguration.loadConfiguration(f);
                            if(course.getString("name").startsWith(String.join(" ", args)))
                                worlds.add(course.getString("name"));
                        }
                    }
                    if(worlds.size() == 0){
                        return null;
                    }
                    return worlds;
                } else {
                    sender.sendMessage(Utils.chat(plugin.getConfig().getString("not_player")));
                }
            }
            return null;
        }
    
    }
    In Main I have this line:

    Code:
    getCommand("join").setTabCompleter(new TabCompleteListener());
    However, when you Tab Complete, it only replaces the last word in the output, as the files in "worlds" have more than one word in the name (Such as "World of A" or "Prism Path") When I tab complete, for example, It goes like this:

    /join
    TAB COMPLETE
    /join A7 Section
    TAB COMPLETE
    /join A7 Chub Chub Section
    TAB COMPLETE
    /join A7 Chub Chub Cooperation
    etc.

    Printing out worlds before returning it with the separator " | " yields:
    A7 Section | Chub Chub Section | Cooperation | Dleltector | Glazed | Iro | Kyoki | Melonaire | etc.
    The worlds are picked up and in separate cells of the list.

    Is there any way to set the Tab Completer to replace all of the args, and not just the last one?
     
  2. Offline

    MightyOne

    You should connect the words of each world name with dashes or any other character. I think this is the only way to make the names iterable.
     
  3. Offline

    Chr0mosom3

Thread Status:
Not open for further replies.

Share This Page