我正在尝试开发一个派系插件,它会为每个运行的命令运行一个脚本。因此,我有一个CommandListner脚本,它由onEnable中的Main.java激活,并且列表器使用参数来确定该命令已运行,并运行一个脚本来执行该命令。
我使用的API可以在这里找到:https://www.spigotmc.org/wiki/buildtools/ (这是1.8版本)
我已经尝试了很多方法来解决此问题,我可以记得错误越来越严重,但是我已经解决了其中的一部分。但我似乎无法找到解决方案。
package net.evolvedmc.evolvedfactions.commands;
import java.awt.Color;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.evolvedmc.evolvedfactions.Main;
public class CommandListner implements CommandExecutor {
private Main plugin;
public CommandListner(Main plugin) {
//Listens for the /f command
this.plugin = plugin;
String STRBaseCMD = "f";
System.out.println("[EvolvedFactions] Listning for command '" + STRBaseCMD + "' with executor " + this);
plugin.getCommand(STRBaseCMD).setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
//Defines our player
Player player = (Player) sender;
//checks if the player has given enough arguments
if(args.length == 0) {
player.sendMessage(Color.RED + "Correct usage: /f <arg>");
return false;
}
//checks if our argument is help
if(args[0].equalsIgnoreCase("help")) {
//checks if the player has the permission to execute this command
if(player.hasPermission("evolvedfactions.default.help")) {
//loads the script wich executes the command
player.sendMessage("BomPom");
new HelpCommand(this, player);
return true;
} else {
player.sendMessage("You do not have permission to execute this command.");
}
}
return false;
}
}
[23:59:56 INFO]: [EvolvedFactions] Enabling EvolvedFactions v0.1
[23:59:56 INFO]: [EvolvedFactions] Activating CommandListner script
[23:59:56 INFO]: [EvolvedFactions] Listning for command 'f' with executor net.evolvedmc.evolvedfactions.commands.CommandListner@6a47bd0b
[23:59:56 ERROR]: Error occurred while enabling EvolvedFactions v0.1 (Is it up to date?)
java.lang.NullPointerException
at net.evolvedmc.evolvedfactions.commands.CommandListner.<init>(CommandListner.java:22) ~[?:?]
at net.evolvedmc.evolvedfactions.Main.onEnable(Main.java:14) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[server.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [server.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [server.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356) [server.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316) [server.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:402) [server.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:370) [server.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:325) [server.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:211) [server.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [server.jar:git-Spigot-c3c767f-33d5de3]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
答案 0 :(得分:2)
您忘记将命令添加到plugin.yml
中(这导致getCommand("f")
返回null
):
main: ...
version: ...
name: ...
commands:
f: