[DEV] PlayerDeathEvent, Error

Discussion in 'Plugin Help/Development/Requests' started by metincasper, Oct 21, 2014.

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

    metincasper

    Hi :)
    I gat this PlayerDeathEvent and i get this error when it's not a player that is the killer.

    Here is the code i use:
    Code:
        @EventHandler
        public void playerdeath(PlayerDeathEvent e) {
            Player pk = e.getEntity().getKiller();
            Entity ek = e.getEntity();
            Player pd = e.getEntity().getPlayer();
            e.getDrops().clear();
            e.setDroppedExp(0);
            String killername = pk.getDisplayName();
           
            if (!(ek instanceof Player)) {
                Bukkit.broadcastMessage("bims");
                return;
            }
           
            int lvl = cf.getData().getInt("Lvl." + pd.getName() + ".lvl");
            pd.setLevel(lvl);
           
            pk.giveExp(+17);
            pk.setHealth(20D);
            pd.sendMessage(ChatColor.RED + killername + " dræbte dig!");
        }

    And here is the error:
    I used the command: /kill for this

    Code:
    [15:32:55 INFO]: xXCalleManXx issued server command: /kill
    [15:32:55 ERROR]: Could not pass event PlayerDeathEvent to LevelUp v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:299) ~[craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerDeat
    hEvent(CraftEventFactory.java:396) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.EntityPlayer.die(EntityPlayer.java:385)
    [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.craftbukkit.v1_7_R4.entity.CraftLivingEntity.setHealth(Cra
    ftLivingEntity.java:85) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.command.defaults.KillCommand.execute(KillCommand.java:33)
    [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    1) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:767) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:1010) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :847) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:65) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184
    ) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    31) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
    Caused by: java.lang.NullPointerException
            at me.xXCalleManXx.levelup.Items.playerdeath(Items.java:38) ~[?:?]
            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:296) ~[craftbukkit-1.7.2-R0.2.jar:git-Spigot-1571]
            ... 20 more
    [15:32:55 INFO]: xXCalleManXx died
    I hope someone can help me :)
     
  2. Offline

    MisterErwin

    metincasper
    a) Wrong section
    b) You are using spigot....
    c) The error occurs here:
    Where is line 38?

    But the reason (I*m just guessing) is: pk can be null, but you are calling
    Code:java
    1. pk.getDisplayName();

    Check if pk is null :)
     
  3. Offline

    eyamaz

    Moved to alternatives section
     
  4. Offline

    BetaNyan

    nu11ch3ck
     
  5. Offline

    Lolmewn

    Check if pk is null. It is when the player is not killed by another player. Do check the Cause of the event and see if it was player-inflicted damage.
     
  6. Offline

    metincasper

    Thanks for the help, i will take a look on it :)
     
Thread Status:
Not open for further replies.

Share This Page