Solved could not pass playerDeathEvent (and I can't find a solved similar problem)

Discussion in 'Plugin Development' started by Levi2251, May 23, 2013.

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

    Levi2251

    I'm making a plugin that will set a config value every time a player dies or kills someone. So far, all I get is a "could not pass playerDeathEvent to plugin" error. I've edited the method which uses playerDeathEvent but to no avail. If you have a minute, would you mind looking this over? I know its in the method, but I just can't find out where.

    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e) {
           
            String killed, killer;
            if(e.getEntity().getKiller() != null && e.getEntity().getKiller().getName() != "")
            {
            killer = e.getEntity().getKiller().getName();
            killer = killer.replace("CraftPlayer{name=", "");
            killer = killer.replace("}", "");
            int kills = m.getConfig().getInt("PVP." + killer + ".Kills");
            kills++;
            m.getConfig().set("PVP."+ killer + ".Kills", kills);
            }
            if(e.getEntity().getKiller() != null && e.getEntity().getKiller().getName() != "") {
            killed = e.getEntity().getName().toString();
            int deaths = m.getConfig().getInt("PVP."+killed+".Deaths");
            deaths++;
            m.getConfig().set("PVP." + killed + ".Deaths", deaths);
            }
    }  
    Sorry about the sloppy code, it looks a bit better in eclipse.

    Edit: Updated the code.
     
  2. Offline

    Nitnelave

    The error you get (could not pass ...) is accompanied by an ugly message called StackTrace. Please print it whole.
     
  3. Offline

    Rhino390

    I've had similar problems with listeners that access a config before. If its an NPE then you just need to initialize your config in your listener.
     
  4. Offline

    Levi2251

    You wouldn't happen to mean this would you?
    Show Spoiler

    Code:
    2013-05-23 22:42:28 [SEVERE] Could not pass event PlayerDeathEvent to plugin
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:340)
        at net.minecraft.server.v1_5_R3.EntityPlayer.die(EntityPlayer.java:293)
        at net.minecraft.server.v1_5_R3.EntityLiving.damageEntity(EntityLiving.java:750)
        at net.minecraft.server.v1_5_R3.EntityHuman.damageEntity(EntityHuman.java:684)
        at net.minecraft.server.v1_5_R3.EntityPlayer.damageEntity(EntityPlayer.java:358)
        at net.minecraft.server.v1_5_R3.EntityLiving.a(EntityLiving.java:978)
        at net.minecraft.server.v1_5_R3.EntityHuman.a(EntityHuman.java:1295)
        at net.minecraft.server.v1_5_R3.Entity.a(Entity.java:772)
        at net.minecraft.server.v1_5_R3.EntityLiving.a(EntityLiving.java:243)
        at net.minecraft.server.v1_5_R3.EntityPlayer.b(EntityPlayer.java:463)
        at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:424)
        at net.minecraft.server.v1_5_R3.Packet10Flying.handle(SourceFile:136)
        at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:109)
        at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at xcyteExtras.PlayerListener.onPlayerDeath(PlayerListener.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 24 more


    Rhino390 Yes, it is an NPE, but its telling me its being caused by the String killer = event.getEntity().getKiller().getName();

    I'm thinking its because when you die from anything other than a player killing you, it returns null, but I've added a not null and not equal to blank check before that code block. I'll update the OP with the updated code.

    Edit: Okay, so, now it doesn't throw the error, but it is not saving the values.

    Fixed it, Thanks guys! The stack trace told me what I needed to know to debug the errors. Marking as solved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  5. Offline

    Ultimate_n00b

    I was just about to say, check if the entity that killed the player is a instanceof player. Otherwise, lots of other ways to die would get in your way.
     
  6. Offline

    Rhino390

    Glad it works for you :D
     
Thread Status:
Not open for further replies.

Share This Page