gpt4 book ai didi

java - 无法传递事件 PlayerJoinEvent

转载 作者:行者123 更新时间:2023-12-02 04:24:00 24 4
gpt4 key购买 nike

[01:48:25 ERROR]: Could not pass event PlayerJoinEvent to Listeners v1.0.0
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.PlayerList.onPlayerJoin(PlayerList.java:272) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.PlayerList.a(PlayerList.java:156) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.LoginListener.b(LoginListener.java:109) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.LoginListener.c(LoginListener.java:41) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.NetworkManager.a(NetworkManager.java:159) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.ServerConnection.c(ServerConnection.java:82) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:800) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
Caused by: java.lang.NullPointerException
at me.spoonle.listeners.join.JoinListener.onJoin(JoinListener.java:30) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
... 14 more

控制台错误消息。

package me.spoonle.listeners.join;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;

import me.spoonle.listeners.Main;
import me.spoonle.listeners.Utils.Utils;

public class JoinListener implements Listener {

private Main plugin;

public JoinListener(Main plugin) {
this.plugin = plugin;

Bukkit.getPluginManager().registerEvents(this, plugin);
}

@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();

if (!p.hasPlayedBefore()) {
e.setJoinMessage(Utils.chat(plugin.getConfig().getString("FirstJoinMessage").replace("%player%", p.getName())));
} else {
e.setJoinMessage(Utils.chat(plugin.getConfig().getString("JoinMessage").replace("%player%", p.getName())));
}
}
@EventHandler
public void onQuit(PlayerQuitEvent q) {
Player p = q.getPlayer();

q.setQuitMessage(Utils.chat(plugin.getConfig().getString("QuitMessage").replace("%palyer%", p.getName())));
}

}

这是我的加入消息和退出消息代码。为什么它不能完全发挥作用?我错过了什么?我需要添加一些东西吗?我正在遵循 YouTube 上的教程,并严格按照步骤进行操作,并与他们的代码进行了三次检查,结果是相同的,所以我很困惑。

最佳答案

显然你的插件在你的 JoinListener 的第 30 列抛出了一个空指针。我猜它可能是 plugin.getConfig().getString("JoinMessage")

来自官方 Spigot 文档 1.14 文档:

FileConfiguration.getString(String path)

If the String does not exist but a default value has been specified, this will return the default value. If the String does not exist and no default value was specified, this will return null.

您的配置中似乎不存在“JoinMessage”条目。

关于java - 无法传递事件 PlayerJoinEvent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56616511/

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