Hello, I have problem with QuitEvent. In "PluginPlayerListener.java" I written: Code: public void onPlayerQuit(PlayerQuitEvent event) { Player pl = event.getPlayer(); if (pl != null) { this.plugin.onQuit(pl); } } In main file: Code: public void onQuit(Player player) { Arena ar = getArena(player); if(ar != null && player != null && player.isOnline() && !player.isDead()) { player.setHealth(0); ar.tasker = 5; } } When player logout all is fine. Works. But... If player died and he went to "title screen" then login I have this error: Code: 2011-12-30 20:43:44 [SEVERE] Could not pass event PLAYER_QUIT to Arena java.lang.NullPointerException at net.minecraft.server.EntityPlayer.closeInventory(EntityPlayer.java:512) at net.minecraft.server.EntityPlayer.die(EntityPlayer.java:185) at org.bukkit.craftbukkit.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:46) at com.orange451.UltimateArena.main.onQuit(main.java:114) at com.orange451.UltimateArena.listeners.PluginPlayerListener.onPlayerQuit(PluginPlayerListener.java:36) at org.bukkit.plugin.java.JavaPluginLoader$2.execute(JavaPluginLoader.java:272) at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:58) at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:339) at net.minecraft.server.ServerConfigurationManager.disconnect(ServerConfigurationManager.java:161) at net.minecraft.server.NetServerHandler.disconnect(NetServerHandler.java:128) at net.minecraft.server.ServerConfigurationManager.attemptLogin(ServerConfigurationManager.java:212) at net.minecraft.server.NetLoginHandler.b(NetLoginHandler.java:88) at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:80) at net.minecraft.server.Packet1Login.a(SourceFile:59) at net.minecraft.server.NetworkManager.b(NetworkManager.java:226) at net.minecraft.server.NetLoginHandler.a(NetLoginHandler.java:46) at net.minecraft.server.NetworkListenThread.a(SourceFile:94) at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:527) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425) at net.minecraft.server.ThreadServerApplication.run(SourceFile:457) Can somebody help me please?
Error is here because after: if(ar != null && player != null && player.isOnline() && !player.isDead()) { player.setHealth(0); ar.tasker = 5; } deleting it's works.
I would do : PluginPlayerListener: Code: public void onPlayerQuit(PlayerQuitEvent e) { Player p = e.getPlayer(); // You don't need a null check here, it will always be a valid player (afaik) this.plugin.onQuit(p); } Main file: Code: public void onQuit(Player player) { if (player != null) { //This is where your null check should go Arena ar = getArena(player); if (ar != null && !player.isDead()) { // Don't check for player.isOnline(), it won't work in this case (as the player has already left) player.setHealth(0); ar.tasker = 5; //Not sure what this is supposed to do } } } Hope I helped?
The exception clarifies that you can't do setHealth on a quitting player that already closed the connection (or something similar to that) - the server will try to schedule a health update packet but it can't. At least that's what I interpret from the stack trace I've no idea how to go around that, though, easiest way would be to instead kill the player when he connects again (onPlayerJoin), I guess.