Command tab completion

Discussion in 'Spigot Plugin Development' started by Xocky, Jan 9, 2020.

  1. how to add an unofficial command to the tab suggestions?
  2. simpleauthority


    I'm not sure what you're asking. You made your own command, and you'd like to tab complete it?

    If you just used onCommand is the JavaPlugin, then also override onTabComplete.

    If you use CommandExecutor, then just also implement TabCompleter (or only implement TabExecutor (combo of CommandExecutor/TabCompleter)).
  3. drives_a_ford


    You override the TabCompleter#onTabComplete method and run your logic there. Your JavaPlugin is the default tab completer for plugin commands, but you can set your own with PluginCommand#setTabCompleter. It's interesting to note, as the javadocs say, If no TabCompleter is specified, and the command's executor implements TabCompleter, then the executor will be used for tab completion.

    Within the method, you'll want to check how many arguments the sender has specified. I recommend using StringUtil.copyPartialMatches to copy your partial matches (case insensitively).
  4. Sorry by "unofficial command" I meant a command that doesn't have Command implemented but is instead checked in
  5. drives_a_ford


    That's not a command.
    As the javadocs clearly state:
    • Agree Agree x 1
  6. Strahan


    Why would you even want to do that instead of a proper command?
  7. Well thanks for pointing out how completely incorrect I was using the PlayerCommandPreprocessEvent

    I rewrote the commands to use CommandExecutor and TabCompleter and now the suggestions work perfectly
    • Like Like x 1