Could any one tell me why I get the exception (and how to fix it):
Bukkit Plugin Couldn't pass Playerdeathevent to Plugin [org.bukkit.event.EventException]
with this code?
@EventHandler
public void ondeath(PlayerDeathEvent event) {
int XP = event.getDroppedExp();
event.setDeathMessage(ChatColor.YELLOW + event.getEntity().getPlayer().getDisplayName() + ChatColor.RED + " was killed by " + ChatColor.YELLOW + event.getEntity().getPlayer().getKiller().getName() + ChatColor.RED + " with a total of " + ChatColor.YELLOW + XP + ChatColor.RED + " XP!");
event.setNewExp(0);
event.setNewLevel(0);
event.getEntity().setGameMode(GameMode.SPECTATOR);
event.getEntity().getPlayer().kickPlayer(ChatColor.BOLD + "" + ChatColor.RED + "You Lost" + ChatColor.RESET + " (Reconnect to spectate, but don't help other Players!)");
for (Player p : Bukkit.getOnlinePlayers()) {
p.playSound(p.getLocation(), Sound.ENDERDRAGON_DEATH, 1, 0);
}
}
EDIT: I know now what the cause was but I don't know what exactly is wrong.
The cause is the following line.
event.setDeathMessage(ChatColor.YELLOW + event.getEntity().getPlayer().getDisplayName() + ChatColor.RED + " was killed by " + ChatColor.YELLOW + event.getEntity().getKiller().getName() + ChatColor.RED + " using " + ChatColor.YELLOW + event.getEntity().getKiller().getPlayer().getItemInHand().getItemMeta().getDisplayName() + ChatColor.RED + " with a total of " + ChatColor.YELLOW + XP + ChatColor.RED + " XP!");
Here is my Error:
16:49:12 [ERROR] Could not pass event PlayerDeathEvent to UHC v0.1
16:49:12 org.bukkit.event.EventException
16:49:12 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:396) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityPlayer.die(EntityPlayer.java:417) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityLiving.damageEntity(EntityLiving.java:812) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityHuman.damageEntity(EntityHuman.java:800) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityPlayer.damageEntity(EntityPlayer.java:496) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityLiving.e(EntityLiving.java:939) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityHuman.e(EntityHuman.java:1440) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.Block.fallOn(Block.java:640) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.Entity.a(Entity.java:811) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityLiving.a(EntityLiving.java:160) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.EntityPlayer.a(EntityPlayer.java:621) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:456) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.PacketPlayInFlying.a(SourceFile:126) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:57) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_65]
16:49:12 at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_65]
16:49:12 at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 at java.lang.Thread.run(Thread.java:745) [?:1.8.0_65]
16:49:12 Caused by: java.lang.NullPointerException
16:49:12 at com.gmail.apply55gx.UHC.Listener.ondeath(Listener.java:40) ~[?:?]
16:49:12 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65]
16:49:12 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_65]
16:49:12 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_65]
16:49:12 at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_65]
16:49:12 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
16:49:12 ... 26 more