java.lang.NullPointerException
启用我的插件时,我得到了以下信息。我真的没有看到问题。
错误:
java.lang.NullPointerException
at tk.mypalsgaming.TARDIScraft.TARDIScraft.onDisable(TARDIScraft.java:31)
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:219)
at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin(JavaPluginLoader.java:481)
at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:401)
at org.bukkit.plugin.SimplePluginManager.disablePlugins(SimplePluginManager.java:394)
at org.bukkit.craftbukkit.v1_6_R2.CraftServer.disablePlugins(CraftServer.java:281)
at net.minecraft.server.v1_6_R2.MinecraftServer.stop(MinecraftServer.java:349)
at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:445)
at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
plugin.yml
:
name: TARDIScraft
main: tk.mypalsgaming.TARDIScraft.TARDIScraft
version: 0.0.1
depend: [Vault]
commands:
tardis:
description: TARDIS Command Block and Admin Command
usage: /<command> <TARDIS command> [parameters]
permission: TARDIScraft.admin
permission-message: You are not a TARDIS Admin, so you do not have access to this command.
TARDIScraft.java
:
package tk.mypalsgaming.TARDIScraft;
import java.util.logging.Logger;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class TARDIScraft extends JavaPlugin {
Logger console = getLogger();
@Override
public void onEnable() {
console.info("Enabling the TARDIS plugin...");
// TODO: onEnable code
}
@Override
public void onDisable() {
console.info("Disabling the TARDIS plugin...");
// TODO: onDisable code
}
public static Permission permission = null;
@SuppressWarnings("unused")
private boolean setupPermissions()
{
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
if (permissionProvider != null) {
permission = permissionProvider.getProvider();
}
return (permission != null);
}
public void onPlayerJoin(PlayerJoinEvent evt) {
Player player = evt.getPlayer();
if ( player.hasPermission("TARDIScraft.admin") ) {
console.info("Admin " + player.getName() + " has joined the game.");
}
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if ( cmd.getName().equalsIgnoreCase("tardis") ) {
boolean senderIsPlayer;
if ( sender instanceof Player ) {
senderIsPlayer = true;
} else senderIsPlayer = false;
// TODO: tardis Command
if ( args[0].equalsIgnoreCase("admin") ) {
Player playerToAdmin = Bukkit.getPlayer(args[1]);
if ( playerToAdmin != null ) {
permission.playerAdd(playerToAdmin, "TARDIScraft.admin");
}
}
return true;
} else {
return false;
}
}
}