Solved Could not pass event PlayerDeathEvent

Discussion in 'Spigot Plugin Help' started by Gobli989, Jul 10, 2018.

  1. Hi there, I'm having a bit of an issue here. I'm trying to make a Stats plugin for my server but whenever someone dies this comes up in the console:

    Code (Text):
    Could not pass event PlayerDeathEvent to SkyDark v1.0.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:396) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityPlayer.die(EntityPlayer.java:417) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityLiving.damageEntity(EntityLiving.java:812) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityHuman.damageEntity(EntityHuman.java:800) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityPlayer.damageEntity(EntityPlayer.java:496) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityLiving.e(EntityLiving.java:939) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityHuman.e(EntityHuman.java:1440) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.Block.fallOn(Block.java:640) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.Entity.a(Entity.java:811) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityLiving.a(EntityLiving.java:160) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.EntityPlayer.a(EntityPlayer.java:621) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:456) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInFlying.a(SourceFile:126) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PacketPlayInFlying$PacketPlayInPosition.a(SourceFile:57) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_171]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_171]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
    Caused by: java.lang.NullPointerException
            at me.gobli989.skydark.Death.onDeath(Death.java:18) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_171]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8-R0.1-SNAPSHOT.jar:git-Spigot-21fe707-e1ebe52]
            ... 26 more

    And this is my code for the Death.jar class:

    Code (Java):
    package me.gobli989.skydark;

    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;

    public class Death implements Listener {

        mysqlSetterGetter m;

        @EventHandler
        public void onDeath(PlayerDeathEvent e) {
            Player player = e.getEntity().getPlayer();
            Player killer = e.getEntity().getKiller().getPlayer();

            if(e.getEntity().getKiller() instanceof Player) {
                int deaths = m.getDeath(player);
                int kills = m.getKills(killer);

                killer.sendMessage(ChatColor.GREEN + "+1 Kills, now you have " + kills);
                player.sendMessage(ChatColor.RED + "+1 Deaths, now you have " + deaths);
            }

            //int deaths = m.getDeath(player);
            //int kills = m.getKills(killer);

            //killer.sendMessage(ChatColor.GREEN + "+1 Kills, now you have " + kills);
            //player.sendMessage(ChatColor.RED + "+1 Deaths, now you have " + deaths);
        }
    }
     

    I would be very thankful if someone could help. <3
     
  2. You have to check if e.getEntity() and e.getEntity().getKiller() are instanceof Player before you initialise them. So initialize m field, that's the cause of the NPE.
     
  3. Benz56

    Moderator Supporter

    Your field m is probably null as well.
    Also the name of mysqlSetterGetter should be MysqlSetterGetter.
     
    • Agree Agree x 1
  4. @Benz56 It's not null, I tried it with numbers and It still not working.
    @javareturn
    I tried this code here:

    Code (Java):
            if(e.getEntity().getKiller() instanceof Player && e.getEntity() instanceof Player) {
                int deaths = 10;
                int kills = 11;

                killer.sendMessage(ChatColor.GREEN + "+1 Kills, now you have " + kills);
                player.sendMessage(ChatColor.RED + "+1 Deaths, now you have " + deaths);


            }
    Also I don't know why I need to check e.getEntity() if It only can be a player.
     
  5. Where have you initialized the m variable? You're not doing this in the current shared class anywhere.
     
  6. mysqlSetterGetter m; is there in the config. It returns just a number from the database. I can replace that with a simple number.
     
  7. Code (Text):
     mysqlSetterGetter m;
    that means nothing. You have to initialise it in the onDeath method.
    m = ...
     
  8. Alright, Thank for you help guys, It's working now!