0

I'm trying to create and "IDE" for minecraft commands. I'm trying to implement command autocomplete and i can't figure out how to do it. That's a try with bukkit:

// Example command
String fullCommand = "fill 3 ";

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

            @Override
            public boolean execute(CommandSender arg0, String arg1, String[] arg2) {
                return false;
            }
        };
        System.out.println(command);
        TabCompleter tabCompleter = getCommand(command).getTabCompleter();
        tabCompleter.onTabComplete(Bukkit.getConsoleSender(), cmd, command, argList.toArray(new String[0]));

I'm getting the following error:

java.lang.NullPointerException
        at de.simonmeusel.mcide.plugin.Plugin.onEnable(Plugin.java:44) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292) ~[s
pigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
.java:340) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
r.java:405) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugin(CraftServer.jav
a:361) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.enablePlugins(CraftServer.
java:321) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.reload(CraftServer.java:74
5) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.Bukkit.reload(Bukkit.java:539) [spigot-1.9.2.jar:git-Spigo
t-e000104-4cb3258]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
25) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
1) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServe
r.java:645) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchServerCommand(Craf
tServer.java:631) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at net.minecraft.server.v1_9_R1.DedicatedServer.aL(DedicatedServer.java:
438) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:4
01) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:6
60) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java
:559) [spigot-1.9.2.jar:git-Spigot-e000104-4cb3258]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_73]

Is there any way to this in bukkit, forge or something else?

Community
  • 1
  • 1
Simon Meusel
  • 200
  • 3
  • 16

2 Answers2

1

try changing:

TabCompleter tabCompleter = getCommand(command).getTabCompleter();

to

getCommand(command).setTabCompleter(new TabCompleter() {

    @Override
    public List<String> onTabComplete(Sender s, Command cmd, String label, String[] args) {
        if(s instanceof ConsoleSender && cmd.equalsIgnoreCase("fill") {
            return argList;
        }
    } 
});

Also remove the last line.

If you have any doubts or if you are having any errors with the code, reply to this answer.

ItzAndree
  • 21
  • 4
  • The thing is: I dont want to set a tab completer for a new command, if wanna see how minecraft would autocomplete a existing command – Simon Meusel Jan 24 '17 at 17:10
  • In that case, I think there is an event for that (TabCompleteEvent, I think) – ItzAndree Jun 09 '18 at 13:49
  • I guess that get's called when a player autocompletes a command. The thing i want, is that I can take a string an see how minecraft would complete it – Simon Meusel Jun 10 '18 at 15:47
  • Then do e.getCompletions(), where e is an instance of TabCompleteEvent – ItzAndree Jun 11 '18 at 19:39
  • For more information, visit [TabCompleteEvent documentation](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/server/TabCompleteEvent.html) – ItzAndree Jun 11 '18 at 20:06
  • But how do I create the event, WITHOUT the user actually pressing tab. I wan't to generate the completions for a string without even a user online – Simon Meusel Jun 12 '18 at 12:26
  • 1
    Before actual sending you the resources, I want you to know that this is **not** a viable solution, because tab completion by some plugins depends on the command sender and its permissions along with other aspects... With this, I mean that **different players could get different tab completions**. So, the way to do it is, [command](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/command/Command.html).[tabComplete](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/command/Command.html#tabComplete-org.bukkit.command.CommandSender-java.lang.String-java.lang.String:A-)(sender, alias, args); – ItzAndree Jul 02 '18 at 21:32
  • 1
    And for the args, sender could be Bukkit.getConsoleSender() and the others could be "" and new String[0] respectively. – ItzAndree Jul 02 '18 at 21:33
  • 1
    Continuing what I said before, that solution is not viable since you can't know exactly what the tab completion for a certain player could be, if he isn't online. That happens because you can't get the CommandSender instance of a player when he goes offline. That is all, _contact me if you need more help_. – ItzAndree Jul 02 '18 at 21:37
  • Thank you, this is exactly what I wanted! If you put it into a new answer, I will mark it as correct. – Simon Meusel Jul 07 '18 at 19:27
-2

(Picture of error) try:

You're getting a Null Pointer, make sure the plugin.yml is outside of the src. Also make sure no errors! And you should be fine. 1. This also depends on what spigot/bukkit jar ur using. 1.9+ has renamed a lot!

kyledrake17
  • 123
  • 1
  • 8