1.15.2 cancel tab suggestions for subcommands. (/help <args>)

Discussion in 'Spigot Plugin Development' started by ComplexCode, Feb 4, 2020.

  1. hello, I want to know if it is possible to cancel the suggestions of the tab in a sub command, for example cancel the suggestions of arguments within the command /help <args>

    I'm sorry if I don't know how to explain.
     
  2. 1. add a tab completer to the command
    2. check if the argument length is the length you want
    3. return an empty iterator
    4. ???
    5. profit
     
  3. For your own commands or for already existing ones?
     
  4. you can do both: JavaPlugin#getCommand ; PluginCommand#setTabCompleter
     
  5. existing
     
  6. Right, in that case, you would have to use the TabCompleteEvent. I would rather not spoonfeed you not too much, but I don't know of a better way of explaining it than with an example.

    Code (Java):
    @EventHandler
    public void onTabCompleteEvent(TabCompleteEvent event) {
        // Here I take the String of event.getBuffer(), which is basically the full line which the player has entered,
        // and I get the first part of it which would be the command that the player has entered.
        String command = event.getBuffer().split(" ").length > 0 ? event.getBuffer().split(" ")[0] : event.getBuffer();
        if(command == ...) { // Here you check if you're dealing with the right command. (Remember that is starts with a slash)
            event.setCompletions(...); // You can set your new tab completions here.
        }
    }
     
    • Useful Useful x 1
  7. Code (Java):
    if(command.equalsIgnoreCase(...)) { // Just change the == for a .equalsIgnoreCase
        e.setCompletions(...);
    }
    it works correctly thanks :D
     
    • Like Like x 1