Predict Command Autocompletion

Discussion in 'Spigot Plugin Development' started by simonmeusel, May 23, 2016.

  1. How can I auto complete a command (gives as a String) like a player would do by pressing tab?

    I have tried this but it does not work:

    String fullCommand = "fill ";

    String command = "";
    List<String> argList = new ArrayList<>();
    for (String string : fullCommand.split(" ")) {
    if (command == "") {
    command = string;
    } else {
    Command cmd = new Command(command) {

    public boolean execute(CommandSender arg0, String arg1, String[] arg2) {
    return false;

    TabCompleter tabCompleter = getCommand(command).getTabCompleter();
    tabCompleter.onTabComplete(Bukkit.getConsoleSender(), cmd, command, argList.toArray(new String[0]));​

    The error:

    at de.simonmeusel.mcide.plugin.Plugin.onEnable( ~[?:?]
    at ~[s
    .java:340) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.craftbukkit.v1_9_R2.CraftServer.loadPlugin(CraftServer.jav
    a:362) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at org.bukkit.craftbukkit.v1_9_R2.CraftServer.enablePlugins(CraftServer.
    java:322) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.MinecraftServer.t(
    16) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.MinecraftServer.l(
    81) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.MinecraftServer.a(
    36) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at net.minecraft.server.v1_9_R2.DedicatedServer.init(DedicatedServer.jav
    a:268) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    :532) [spigot-1.9.4.jar:git-Spigot-8a048fe-a022dd2]
    at [?:1.8.0_73]​

    Line 44:
    TabCompleter tabCompleter = getCommand(command).getTabCompleter();​

    I guess getCommand("fill") returns null.

    So i tried registering a command in the plugin.yml and go with tahat but that gives the same error.

    Any ideas?
  2. Choco


    Nope. .getTabCompleter() returns null. What you want to do, is create a class that "implements TabCompleter". Just go from there. It's quite simple.

    To register the tab completer, you do the same thing as registering a command in your onEnable. this.getCommand("").setTabCompleter(new YourTabCompletionClass())
    • Like Like x 1
  3. I don't wan't to create my own tab completer, I want to get the tabCompleter of for example the /fill command
  4. I think NMS handles it differently.

    Gesendet von meinem Nexus 5 mit Tapatalk
    • Agree Agree x 1
  5. What do you mean with NMS?
  6. Net Minecraft Server.
    • Informative Informative x 2
  7. This is what you want:

    You make a class implementing TabExecutor, and you will have to implement two methods, one is for the command and the other is for tab complete. The onCommand method works like any regular onCommand. The TabCompletor works very similarly, all you have to do is detect how many arguments the player has typed and then return a list of all possibilities based on which argument they are on.
  8. No that is not what i want. I dont want to create my own command with tab executer, i want to get a tab executor of /fill or other minecraft command, so i could get the list for /fill 2 56 2 min...
  9. You could use a CommandPreProcessEvent or something like that, then check the commands and the arguments.