当尝试从 GUI 设置播放器后缀/前缀时,我得到一个用于设置所述前缀/后缀的空指针异常。(我收到“您应用了 x 标签”消息,它确实关闭了库存。)
主类(定义和设置聊天的地方,而不是整个类)
public static Chat chat = null;
@SuppressWarnings("unused")
private TagsCommands tCmd;
public void onEnable() {
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
setupChat();
createFolders();
Message.console("&fPlugin successfully loaded");
Bukkit.getPluginManager().registerEvents(new TagsGUI(), this);
tCmd = new TagsCommands(this);
} else {
Message.console("&dCouldn't enable plugin as &aVault&c was not found");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
}
private boolean setupChat() {
RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager()
.getRegistration(net.milkbowl.vault.chat.Chat.class);
if (chatProvider != null) {
chat = chatProvider.getProvider();
}
return (chat != null);
}
GUI 类(同样,不是全部。错误在于第 55 行的此类。)
@EventHandler
public void inventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
ItemStack click = event.getCurrentItem();
if (opened.contains(player)) {
event.setCancelled(true);
File tags = new File("plugins/Tags/Pages", "One.yml");
FileConfiguration tagsC = YamlConfiguration.loadConfiguration(tags);
for (String title : tagsC.getConfigurationSection("Tags").getKeys(false)) {
String tag = tagsC.getString("Tags." + title + ".Display");
if (click.getItemMeta().getDisplayName().equals(Format.color(tag))) {
if (player.hasPermission(tagsC.getString("Tags." + title + ".Permission"))) {
if (tagsC.getString("Tags." + title + ".Type").equalsIgnoreCase("prefix")) {
player.closeInventory();
Message.player("&fYou applied the '" + tag + "&f' tag", player);
Main.chat.setPlayerPrefix(player, Format.color(tag));
break;
} else if (tagsC.getString("Tags." + title + ".Type").equalsIgnoreCase("suffix")) {
player.closeInventory();
Message.player("&fYou applied the '" + tag + "&f' tag", player);
Main.chat.setPlayerSuffix(player, Format.color(tag));
break;
}
} else {
Message.player("&fSorry, but you do not have permission to do this", player);
break;
}
}
}
return;
}
}
第 55 行:Main.chat.setPlayerSuffix(player, Format.color(tag));
控制台错误信息:
[11:13:05 INFO]: BearToothh issued server command: /tags
[11:13:12 ERROR]: Could not pass event InventoryClickEvent to Tags v1.0
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1889) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:33) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:10) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
at java.lang.Thread.run(Unknown Source) [?:?]
Caused by: java.lang.NullPointerException
at me.askingg.tags.TagsGUI.inventoryClick(TagsGUI.java:55) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-2b93d83]
... 15 more