Need help with PlayerDeathEvent

Discussion in 'Plugin Development' started by trikxgaming, Jul 1, 2014.

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

    trikxgaming

    So im remaking HG plugins and i cant seem to solve this error. Ik its simple but can someone help im stuck.


    Here is the error it gives me
    [12:31:03 ERROR]: Could not pass event PlayerDeathEvent to tHG v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.event.CraftEventFactory.callPlayerDeat
    hEvent(CraftEventFactory.java:345) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974j
    nks]
    at net.minecraft.server.v1_7_R1.EntityPlayer.die(EntityPlayer.java:368)
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityLiving.damageEntity(EntityLiving.j
    ava:732) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityHuman.damageEntity(EntityHuman.jav
    a:746) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityPlayer.damageEntity(EntityPlayer.j
    ava:446) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.BlockCactus.a(BlockCactus.java:92) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.Entity.I(Entity.java:755) [craftbukkit.j
    ar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.Entity.move(Entity.java:413) [craftbukki
    t.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityLiving.e(EntityLiving.java:1210) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityHuman.e(EntityHuman.java:1259) [cr
    aftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityLiving.e(EntityLiving.java:1466) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityHuman.e(EntityHuman.java:390) [cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityLiving.h(EntityLiving.java:1299) [
    craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityHuman.h(EntityHuman.java:162) [cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.EntityPlayer.i(EntityPlayer.java:240) [c
    raftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :342) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInFlying.a(SourceFile:137) [cr
    aftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.PacketPlayInFlying.handle(SourceFile:8)
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.NullPointerException
    at me.trikxgaming.hg.DeathListener.onDeath(DeathListener.java:27) ~[?:?]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0
    _10]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0
    _10]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .7.0_10]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_10]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    ... 28 more
    [12:31:03 INFO]: TRiKxGAMING was pricked to death
    >


    Then here is my code in PlayerDeathEvent
    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent e) {
    3. e.getDrops().clear();
    4. Player p = e.getEntity();
    5. if(plugin.kitused.contains(p.getName())) {
    6. plugin.kitused.remove(p.getName());
    7. plugin.kangaroo.remove(p.getName());
    8. plugin.berserker.remove(p.getName());
    9. plugin.cookiemonster.remove(p.getName());
    10.  
    11. }
    12. Player killer = p.getKiller();
    13. if(plugin.berserker.contains(killer.getName())){
    14. if(p instanceof Player){
    15. killer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 2));
    16. killer.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 7, 1));
    17. }
    18. }
    19. e.getDrops().clear();
    20. }


    Help?
     
  2. Offline

    fireblast709

    trikxgaming killer is null when the player dies of natural causes
     
  3. Offline

    trikxgaming

    so should i say if (killer == null) { return; } ?
     
  4. Offline

    teej107

    trikxgaming Or just add that in another if statement, no return; needed. Except check to see if the player isn't null instead.
     
  5. Offline

    trikxgaming


    Code:java
    1. if(plugin.berserker.contains(killer.getName())){
    2.  
    3. if(!(killer == null)) {
    4. killer.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 2));
    5. killer.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 20 * 7, 1));
    6. }
    7. }

    Doesnt work.
     
  6. Offline

    teej107

    trikxgaming Add it in below the code where you initialize killer, not where you put it. Have that if statement surround the code you just posted. Checking to see if killer is null is only effective before you use anything from the player.
     
  7. Offline

    trikxgaming

    I got it I have to use entitydeathevent
     
  8. Offline

    teej107

  9. Offline

    tommyhoogstra

    Instead of doing that, just do

    Code:java
    1. if(killer != null){
    2.  
    3. }
     
Thread Status:
Not open for further replies.

Share This Page