Minecraft One Player Per Config

时间:2015-07-20 04:13:07

标签: java bukkit

我打算尽快做这个,我试图为每个玩家制作一个配置。

所以基本上我什么时候调用user.CreateUser();如果用户不存在,它会在那里注册自己的配置,其中唯一的id作为yml的名称

我的问题是,当我尝试调用user.CreateUser();在PlayerJoinEvent上它显示错误,我不确定 UUID u 不应该返回null,因为它在构造函数或其他变量中。

错误

==

CreateUser Listener Class

__eq__

UserDataHandler类

[23:57:52 ERROR]: Could not pass event PlayerJoinEvent to MCEnhanced v1.0
org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
va:310) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
a:62) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
ava:502) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
ava:487) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:
296) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:156) [spigo
t-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144)
[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54) [
spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231
) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java
:148) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:8
17) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
67) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
57) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
:560) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.NullPointerException
        at crypted.mcenhanced.Handlers.UserDataHandler.CreateUser(UserDataHandle
r.java:46) ~[?:?]
        at crypted.mcenhanced.Mechanics.ConfigMechanics.CreateUser.CreateUser(Cr
eateUser.java:19) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
_45]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
_45]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
.8.0_45]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
va:306) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-f928e7a-e91aed8]
        ... 14 more

1 个答案:

答案 0 :(得分:1)

CreateUser方法中,您引用了当前UserFile对象的UserDataHandler 字段或实例变量,默认情况下为null。 UserDataHandler类的构造函数不会实例化此UserFile字段,而是在该构造函数中创建一个本地File变量,然后从不使用该变量。这条线...

File UserFile = new File("plugins/MCEnhanced/data/" + u + ".yml");

应该是......

UserFile = new File("plugins/MCEnhanced/data/" + u + ".yml");

以便为该实例实例化File字段。

我建议使用lowerCamelCase命名约定来命名变量,字段和方法。