Null pointer on Death

Discussion in 'Plugin Development' started by arnie231, Sep 10, 2012.

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


    Heres the code & Error

    1. package com.arnie.sh2.Listeners;
    3. import com.arnie.sh2.Main;
    4. import net.milkbowl.vault.economy.EconomyResponse;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.PlayerDeathEvent;
    13. public class PlayerDeath implements Listener
    14. {
    15. @EventHandler(priority=EventPriority.NORMAL)
    16. public void DeathCharge(PlayerDeathEvent event){
    17. if (event.getEntity() instanceof Player){
    18. Player player = event.getEntity();
    19. if (player.hasPermission("Stronghold2.Death.Exempt")){
    20. return;
    21. }
    22. if (Main.Config.getBoolean("Stronghold2.Economy.Enabled")){
    23. double amount = Main.Config.getLong("Stronghold2.Death.Price");
    24. EconomyResponse er = Main.economy.withdrawPlayer(player.getName(), amount);
    25. if (er.transactionSuccess()){
    26. player.sendMessage(ChatColor.GOLD + "[Stronghold2]" + " " + ChatColor.RED + "You lost" + " " + ChatColor.GREEN + amount + " " + "for Dieing!");
    27. }else{
    28. player.sendMessage(ChatColor.GOLD + "[Stronghold2]" + " " + ChatColor.DARK_RED + "An error occured if your seeing this contact an Admin!");
    29. }
    30. return;
    31. }
    33. }
    34. }
    35. }

    2012-09-10 23:32:28 [SEVERE] Could not pass event PlayerDeathEvent to Stronghold2
    at org.bukkit.plugin.RegisteredListener.callEvent(
    at org.bukkit.plugin.SimplePluginManager.fireEvent(
    at org.bukkit.plugin.SimplePluginManager.callEvent(
    at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerDeathEvent(
    at net.minecraft.server.EntityPlayer.die(
    at net.minecraft.server.EntityLiving.damageEntity(
    at net.minecraft.server.EntityHuman.damageEntity(
    at net.minecraft.server.EntityPlayer.damageEntity(
    at net.minecraft.server.EntityHuman.attack(
    at net.minecraft.server.NetServerHandler.a(
    at net.minecraft.server.Packet7UseEntity.handle(SourceFile:36)
    at net.minecraft.server.NetworkManager.b(
    at net.minecraft.server.NetServerHandler.d(
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(
    at net.minecraft.server.DedicatedServer.q(
    at net.minecraft.server.MinecraftServer.p(
    Caused by: java.lang.NullPointerException
    at com.arnie.sh2.Listeners.PlayerDeath.DeathCharge(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    ... 20 more
  2. Offline


  3. Offline


    Here is a hint:
    Caused by: java.lang.NullPointerException
    at com.arnie.sh2.Listeners.PlayerDeath.DeathCharge(
  4. Offline


  5. Offline


    Main.economy is null. you should actually read the stack trace next time. 9 times out of 10 whenever i have a problem i post here, it doesnt involve a stacktrace.
  6. Offline


    You will have to learn reading stacktraces. Those nulls pop out too often. Even for a experienced programmers.
    I even gave you a hint... that points directly to the line where the exception originated. What else do you need?

    Stacktraces are relatively easy to read and usually give all the required information. If you still don’t find what the problem is then use System.out.println() to check if the the different elements from the given line are null.

    That post was made for a reason.

    The only thing worse than "halp, i got a nullpointerexception!!!!" is "halp, it doesnt compile!!!"
    CorrieKay likes this.
  7. Offline


    Fixed the issue

    After Player player = event.getEntity();

    i need to add

    Player player = event.getEntity().getPlayer();
Thread Status:
Not open for further replies.

Share This Page