Solved adding colors in tab completion?

Discussion in 'Spigot Plugin Development' started by Swiftlicious, Jan 20, 2020.

Thread Status:
Not open for further replies.
  1. Code (Text):
                } else if (cmd.getName().equalsIgnoreCase("help")) {
             
                    if (args.length == 1) {
                     
                        ArrayList<String> helplist = new ArrayList<String>();
                     
                        helplist.add("stats");
                        helplist.add("vote");
                        helplist.add("achievements");
                        helplist.add("teamchat");
                        helplist.add("team");
                        helplist.add("timezone");
                        helplist.add("msg");
                        helplist.add("guild");
                        helplist.add("leaderboards");
                        helplist.add(String.valueOf(1));
                        helplist.add(String.valueOf(2));
                        helplist.add(String.valueOf(3));
                     
                        for (String help : helplist) {
                            if (help.toLowerCase().startsWith(args[0].toLowerCase())) {
                                completions.add(Chat.color("&a" + help + "&7"));
                            }
                        }
                     
                        completions.add("");
                    }
                 
                    Collections.sort(completions);
                    return completions;
             
                    }
    What i want the outcome to be when pressing tab is it to show as green for the argument and grey for the comma instead of it all being just white. But when I do this it will autocomplete the argument including whatever symbol I use so if I use &a here for example the argument will show as "astats7" for example. Is there a way to make it show color but not include the symbol? I've tried using ChatColor enums as well (getting the same issue) and doing stripColor or substrings but that would eliminate the color entirely.
     
  2. I think you have to register the command completion (or the command entirely) through Mojang Brigadier.
    You can also use an helper plugin like Commodore, that you can find here: https://github.com/lucko/commodore
    I sincerely don’t know how to use it, I’m going to test it this afternoon (considering Italian time).
     
  3. Never mind, i saw now the version, 1.12.2 doesn’t support brigadier...
    I’m stupid, I should watch the version before posting.
    Sorry
     
    • Funny Funny x 1
  4. Well I didn't even know it was possible to get colors inside the actual command box when tabbing your completion arguments, what I meant was more along the lines of this:
    [​IMG]
    where as you can see my argument is returning an "a" and a "7" at the end from the &a and &7 color codes I added.
     
  5. This because, I think, chat doesn’t really use color codes. In 1.13+ there are actually colors, but are formatted in other ways. I suggest you to switch to 1.13+, so you can use commodore and brigadier.
     
    • Informative Informative x 1
Thread Status:
Not open for further replies.