我正在尝试创建和" IDE"对于我的世界命令。我试图实现命令自动完成,但我无法弄清楚如何做到这一点。尝试使用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]));
我收到以下错误:
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]
在bukkit,forge或其他方面有没有办法解决这个问题?
答案 0 :(得分:0)
尝试改变:
TabCompleter tabCompleter = getCommand(command).getTabCompleter();
到
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;
}
}
});
同时删除最后一行。
如果您有任何疑问或者您对代码有任何错误,请回答此答案。
答案 1 :(得分:-3)
您正在获取Null指针,请确保plugin.yml位于src之外。 还要确保没有错误!而你应该没事。 这也取决于你使用的插口/ bukkit罐子。 1.9+已经重命名了很多!