gpt4 book ai didi

java - Bukkit - 使用 VaultAPI 的 NPE(聊天)

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:06 25 4
gpt4 key购买 nike

当尝试从 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

最佳答案

public static Chat chat = null;null,因此它返回 NullPointerException。您不能定义一个空的聊天并在不存在的聊天上设置前缀和内容^^您必须将 Chat chat 变量定义为现有聊天。

关于java - Bukkit - 使用 VaultAPI 的 NPE(聊天),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52553118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com