Could not pass event PlayerDeathEvent

Discussion in 'Plugin Help/Development/Requests' started by DubstepPrins, Dec 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    DubstepPrins

    Hai der.
    I'm trying to code a deathmessage plugin but everytime a player dies, I get an error which I normally should not get because there are no eclipse errors + the message come's in chat.
    Can someone help me please?
    ERROR:
    Show Spoiler
    [20:52:21 ERROR]: Could not pass event PlayerDeathEvent to Deathmessage v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:302) ~[spigot.jar:git-Spigot-1649]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot.jar:git-Spigot-1649]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:514) [spigot.jar:git-Spigot-1649]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:499) [spigot.jar:git-Spigot-1649]
    at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerDeat
    hEvent(CraftEventFactory.java:397) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityPlayer.die(EntityPlayer.java:386)
    [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityLiving.damageEntity(EntityLiving.j
    ava:745) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityHuman.damageEntity(EntityHuman.jav
    a:765) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityPlayer.damageEntity(EntityPlayer.j
    ava:465) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntitySlime.b_(EntitySlime.java:202) [sp
    igot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityHuman.d(EntityHuman.java:452) [spi
    got.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityHuman.e(EntityHuman.java:444) [spi
    got.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityLiving.h(EntityLiving.java:1409) [
    spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityHuman.h(EntityHuman.java:164) [spi
    got.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.EntityPlayer.i(EntityPlayer.java:258) [s
    pigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :357) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.PacketPlayInFlying.a(SourceFile:137) [sp
    igot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.PacketPlayInPosition.handle(PacketPlayIn
    Position.java:35) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186
    ) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [spigot.jar:git-Spigot-1649]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [spigot.jar:git-Spigot-1649]
    Caused by: java.lang.NullPointerException
    at me.dubstepprins.deathmessage.events.PlayerKill.onPlayerDeath(PlayerKi
    ll.java:13) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:298) ~[spigot.jar:git-Spigot-1649]
    ... 24 more

    Code:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent c) {
    3. if(c.getDeathMessage().contains("was blown up by Creeper")) {
    4. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was blown up by " + ChatColor.RED + "CREEPER" + ChatColor.GOLD + "!");
    5. }
    6. if(c.getDeathMessage().contains("was shot by Skeleton")) {
    7. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was shot by " + ChatColor.RED + "SKELETON" + ChatColor.GOLD + "!");
    8. }
    9. if(c.getDeathMessage().contains("was slain by Spider")) {
    10. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "SPIDER" + ChatColor.GOLD + "!");
    11. }
    12. if(c.getDeathMessage().contains("was slain by Zombie")) {
    13. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "ZOMBIE" + ChatColor.GOLD + "!");
    14. }
    15. if(c.getDeathMessage().contains("was slain by Slime")) {
    16. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "SLIME" + ChatColor.GOLD + "!");
    17. }
    18. if(c.getDeathMessage().contains("was fireballed by Ghast")) {
    19. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was fireballed by " + ChatColor.RED + "GHAST" + ChatColor.GOLD + "!");
    20. }
    21. if(c.getDeathMessage().contains("was slain by Zombie Pigman")) {
    22. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "ZOMBIE PIGMAN" + ChatColor.GOLD + "!");
    23. }
    24. if(c.getDeathMessage().contains("was slain by Enderman")) {
    25. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "ENDERMAN" + ChatColor.GOLD + "!");
    26. }
    27. if(c.getDeathMessage().contains("was slain by Cave Spider")) {
    28. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "CAVE SPIDER" + ChatColor.GOLD + "!");
    29. }
    30. if(c.getDeathMessage().contains("was slain by Silverfish")) {
    31. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "SILVERFISH" + ChatColor.GOLD + "!");
    32. }
    33. if(c.getDeathMessage().contains("was burnt to a crisp whilst fighting Blaze")) {
    34. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was burnt to a crisp by " + ChatColor.RED + "BLAZE" + ChatColor.GOLD + "!");
    35. }
    36. if(c.getDeathMessage().contains("was slain by Magma Cube")) {
    37. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "MAGMA CUBE" + ChatColor.GOLD + "!");
    38. }
    39. if(c.getDeathMessage().contains("was killed by Witch using magic")) {
    40. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "WITCH" + ChatColor.GOLD + " using magic" + ChatColor.GOLD + "!");
    41. }
    42. if(c.getDeathMessage().contains("was slain by Wolf")) {
    43. c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was killed by " + ChatColor.RED + "WOLF" + ChatColor.GOLD + "!");
    44. }
    45. }
    46. }

    Thanks.
     
  2. Offline

    mine-care

    You could use death cause instead of checking if the death message contains something,
    What is line 13 in that class?
    Also I see spigot @,..,@
     
  3. Offline

    DubstepPrins

    mine-care Spigot is because I couldn't run bukkit otherwise :p DMCA stuff but line 13:
    Code:
    c.setDeathMessage(ChatColor.GREEN + c.getEntity().getName() + ChatColor.GOLD + " was blown up by " + ChatColor.RED + "CREEPER" + ChatColor.GOLD + "!");
    And how would I find the cause of death? (I mean c.(insterstuff here))
     
  4. Offline

    Googlelover1234

    DubstepPrins
    So, I'm going to guess that c.getEntity() can return null, do some null checks:

    Code:
    if(c.getEntity() instanceof Player) {
    // Safely cast Player to entity
    // Death message stuff
    }
     
Thread Status:
Not open for further replies.

Share This Page