无法通过事件PlayerJoinEvent

时间:2019-06-16 06:04:04

标签: java eclipse plugins minecraft

[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上观看了一个教程,并严格按照步骤进行操作,并用它们的代码对我的代码进行了三倍检查,结果是一样的,所以我很困惑。

1 个答案:

答案 0 :(得分:0)

很明显,您的插件在第30列的JoinListener中抛出了一个Nullpointer。 我猜可能是plugin.getConfig().getString("JoinMessage")

来自官方的Spigot文档1.14文档:

FileConfiguration.getString(String path)

  

如果字符串不存在,但已指定默认值,   这将返回默认值。如果字符串不存在,并且   没有指定默认值,它将返回null。

您的配置中似乎没有“ JoinMessage”条目。