我一直坚持这个错误大约半个小时,现在试图找出导致它的原因,以及如何解决它。如果你能在这两个问题上给我答案,我们将不胜感激。
这是我的主要课程。
package me.galaxywarrior6.minecraftgta;
import java.util.Arrays;
import me.galaxywarrior6.minecraftgta.commands.GangCreateCommand;
import me.galaxywarrior6.minecraftgta.events.AmmoBuyEvents;
import me.galaxywarrior6.minecraftgta.events.EntityEvents;
import me.galaxywarrior6.minecraftgta.events.PlayerEvents;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
public class MinecraftGTA extends JavaPlugin{
public static FileConfiguration config;
public static MinecraftGTA plugin = null;
@Override
public void onEnable(){
getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
getServer().getPluginManager().registerEvents(new EntityEvents(), this);
getServer().getPluginManager().registerEvents(new AmmoBuyEvents(), this);
getCommand("gangs").setExecutor(new GangCreateCommand(this));
System.out.println("[Minecraft GTA] Made by galaxywarrior6");
System.out.println("[Minecraft GTA] Re-wrote and improved by I_Stole_The_Sock");
this.saveDefaultConfig();
config = getConfig();
plugin = this;
config.set("gangs.list", Arrays.asList());
}
@Override
public void onDisable(){
System.out.println("[Minecraft GTA] Made by galaxywarrior6");
System.out.println("[Minecraft GTA] Re-wrote and improved by I_Stole_The_Sock");
this.saveConfig();
}
public static void saveFile(){
plugin.saveConfig();
}
}
这是我的GangCreateCommand类。
package me.galaxywarrior6.minecraftgta.commands;
import me.galaxywarrior6.minecraftgta.MinecraftGTA;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class GangCreateCommand implements CommandExecutor{
public MinecraftGTA plugin;
public GangCreateCommand(MinecraftGTA instance){
plugin = instance;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]){
Player p = (Player) sender;
if (cmd.getName().equalsIgnoreCase("gangs")){
String prefix = ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Gangs" + ChatColor.DARK_GRAY + "] ";
if (MinecraftGTA.config.getList("gangs.list").contains(args[0])){
p.sendMessage(prefix + ChatColor.RED + "That gang name is already taken!");
return true;
}
String UUID = p.getUniqueId().toString();
if (!(MinecraftGTA.config.getString(UUID + ".Gang") == "None")){
p.sendMessage(prefix + ChatColor.RED + "You're already in a gang!");
return true;
}
if (args[0].equalsIgnoreCase("create")){
MinecraftGTA.config.set(UUID + ".Gang", args[0]);
MinecraftGTA.config.set(UUID + ".GangOwnership", args[0]);
MinecraftGTA.config.set(UUID + ".GangRank", "Owner");
MinecraftGTA.config.getStringList("gangs").add(args[0]);
p.sendMessage(prefix + ChatColor.GREEN + "You've successfully created a gang!");
p.sendMessage(prefix + ChatColor.GREEN + "Type /gangs invite (username) to invite a player to join your gang!");
Bukkit.getServer().broadcastMessage(prefix + ChatColor.LIGHT_PURPLE + p.getName() + ChatColor.GREEN + " has started up a gang!");
return true;
}
}
return true;
}
}
这是错误日志
10.04 01:27:35 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:175) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:275) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:319) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:342) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:282) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:300) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:384) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:350) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.2-16-gb12f12f-b2996jnks]
10.04 01:27:35 [Server] INFO at me.galaxywarrior6.minecraftgta.MinecraftGTA.onEnable(MinecraftGTA.java:25) ~[?:?]
10.04 01:27:35 [Server] INFO java.lang.NullPointerException
10.04 01:27:35 [Server] ERROR Error occurred while enabling Minecraft GTA v0.3 (Is it up to date?)
答案 0 :(得分:0)
您的错误在于:getCommand("gangs").setExecutor(new GangCreateCommand(this));
如果你看到这个类的代码:org.bukkit.plugin.java.JavaPlugin;你会看到:
public PluginCommand getCommand(String name) {
String alias = name.toLowerCase();
PluginCommand command = getServer().getPluginCommand(alias);
if ((command != null) && (command.getPlugin() != this)) {
command = getServer().getPluginCommand(description.getName().toLowerCase() + ":" + alias);
}
if ((command != null) && (command.getPlugin() == this)) {
return command;
} else {
return null;
}
}
所以这个方法可以返回null,你必须捕获异常。
答案 1 :(得分:0)
问题是你从未在plugin.yml中指定命令,或者你完全省略了你的plugin.yml。这是整个插件jar中最重要的文件。
有关plugin.yml的更多信息,请点击此处: