Plugin Help java.lang.NullPointerException.......

Discussion in 'Plugin Help/Development/Requests' started by TehCoderHD, Jul 20, 2015.

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

    TehCoderHD

    Help me please.

    I have this error in my pvp plugin:
    HELP (open)

    20:51:21 [ERROR] Could not pass event PlayerDeathEvent to Minedeck_PvP v1.0
    20:51:21 org.bukkit.event.EventException
    20:51:21 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:381) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.EntityPlayer.die(EntityPlayer.java:407) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.EntityLiving.damageEntity(EntityLiving.java:765) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.EntityHuman.damageEntity(EntityHuman.java:801) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.EntityPlayer.damageEntity(EntityPlayer.java:486) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.EntityArrow.s_(EntityArrow.java:244) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.World.entityJoinedWorld(World.java:1588) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.World.g(World.java:1563) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.World.tickEntities(World.java:1410) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.WorldServer.tickEntities(WorldServer.java:577) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:757) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 at java.lang.Thread.run(Unknown Source) [?:1.7.0_71]
    20:51:21 Caused by: java.lang.NullPointerException
    20:51:21 at me.minedeck.pvp.methods.Stats.giveDeath(Stats.java:23) ~[?:?]
    20:51:21 at me.minedeck.pvp.listener.KillDeathListener.onDeath(KillDeathListener.java:20) ~[?:?]
    20:51:21 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_71]
    20:51:21 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
    20:51:21 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_71]
    20:51:21 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_71]
    20:51:21 at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot-1.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-29dbaa7-262c777]
    20:51:21 ... 18 more
    2


    I have multiple classes in my PlayerDeathEvent:

    Stats Class:
    Code:
    package me.minedeck.pvp.methods;
    
    import me.minedeck.pvp.PvP;
    
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    
    public class Stats {
       
        static PvP plugin;
       
        public static void giveKill(Player p, int i) {
            plugin.getConfig().set(p.getUniqueId().toString() + ".kills",
                    Integer.valueOf(plugin.getConfig().getInt(p.getUniqueId().toString() + ".kill", 0) + i));
            plugin.saveConfig();
        }
        public static void giveDeath(Player p, int i) {
            plugin.getConfig().set(p.getUniqueId().toString() + ".deaths",
                    Integer.valueOf(plugin.getConfig().getInt(p.getUniqueId().toString() + ".death", 0) + i));
            plugin.saveConfig();
        }
       
        public static void addKillstreak(Player p, int i) {
            plugin.getConfig().set(p.getUniqueId().toString() + ".killstreaks",
                    Integer.valueOf(plugin.getConfig().getInt(p.getUniqueId().toString() + ".killstreak", 0) + i));
            plugin.saveConfig();
        }
       
        public static void endKillstreak(Player p){
            String uuid = p.getUniqueId().toString();
            plugin.getConfig().set(p.getUniqueId().toString() + ".killstreaks",
                    Integer.valueOf(plugin.getConfig().getInt(p.getUniqueId().toString() + ".killstreak", 0) - plugin.getConfig().getInt(uuid + ".killstreak")));
            plugin.saveConfig();
        }
       
    
       
       
       
       
       
       
    }
    PvPPlayer class:
    Code:
    package me.minedeck.pvp.methods;
    
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class PvPPlayer {
        public static void setINV(Player p){
            p.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
            p.getInventory().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
            p.getInventory().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
            p.getInventory().setBoots(new ItemStack(Material.GOLD_BOOTS));
           
            ItemStack ffasword = new ItemStack(Material.IRON_SWORD);
            ItemStack ffabow = new ItemStack(Material.BOW);
            ItemStack ffarod = new ItemStack(Material.FISHING_ROD);
            ItemStack ffaarrow = new ItemStack(Material.ARROW);
           
            ItemMeta swordmeta = ffasword.getItemMeta();
            ItemMeta bowmeta = ffabow.getItemMeta();
            ItemMeta rodmeta = ffarod.getItemMeta();
            ItemMeta arrowmeta = ffaarrow.getItemMeta();
           
            swordmeta.setDisplayName("§a-§7= §cSword §7=§a-");
            bowmeta.setDisplayName("§a-§7= §cBow §7=§a-");
            rodmeta.setDisplayName("§a-§7= §cRod §7=§a-");
            arrowmeta.setDisplayName("§a-§7= §cArrow §7=§a-");
           
            ffasword.setItemMeta(swordmeta);
            ffabow.setItemMeta(bowmeta);
            ffarod.setItemMeta(rodmeta);
            ffaarrow.setItemMeta(arrowmeta);
           
            ffabow.addEnchantment(Enchantment.ARROW_INFINITE, 1);
            ffarod.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1);
           
            p.getInventory().setItem(0, ffasword);
            p.getInventory().setItem(1, ffabow);
            p.getInventory().setItem(2, ffarod);
            p.getInventory().setItem(8, ffaarrow);
           
           
        }
       
        public static void playDeathSound(Player p){
            p.playSound(p.getLocation(), Sound.GHAST_SCREAM, 10.0F, -10.0F);
           
        }
       
        public static void playKillSound(Player p){
            p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 10.0F, -10.0F);;
        }
    }
    
    Tokens Class:

    Code:
    package me.minedeck.pvp.methods;
    
    
    import me.minedeck.pvp.PvP;
    
    import org.bukkit.entity.Player;
    
    public class Tokens {
         static PvP plugin;
       
        public static void giveCredit(Player p, int i) {
            plugin.getConfig().set(p.getUniqueId().toString() + ".credit",
                    Integer.valueOf(plugin.getConfig().getInt(p.getUniqueId().toString() + ".credit", 0) + i));
            plugin.saveConfig();
        }
       
       public static boolean hasCredit(Player p, int i) {
             if (plugin.getConfig().getInt(p.getUniqueId().toString() + ".credit") >= i) {
                 return true;
             }
             return false;
       }
       
        public static void removeCredit(Player p, int i) {
            plugin.getConfig().set(p.getUniqueId().toString() + ".credit",
                    Integer.valueOf(plugin.getConfig().getInt(p.getUniqueId().toString() + ".credit", 0) - i));
            plugin.saveConfig();
        }
    }
    
    Thank you in advance

    bump bump bump

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

    Boomer

    20:51:21 Caused by: java.lang.NullPointerException
    20:51:21 at me.minedeck.pvp.methods.Stats.giveDeath(Stats.java:23) ~[?:?]

    That is where your error is, so your
    Code:
        plugin.getConfig().set(p.getUniqueId().toString() + ".deaths",      
              Integer.valueOf(plugin.getConfig().getInt(p.getUniqueId().toString() + ".death", 0) + i));
    
    So at this point in execution, you have a null while dereferencing things, or acting on a null.
    So examine the line for possibilities:
    1) plugin may not be set at this point in execution causing null
    2) plugin.getConfig() would be available If plugin is, so that is not likely
    3) .set will create a record if it does not exist, so it does not care what the argument key is as long as it is creatable
    4) plugin.getConfig().getInt always works provided that the key exists
    5) p.getUnique().toString() .. the .toString() will always work for any value that is returned, and there will ALWAYS be a value returned for a player object, but..it will throw a null if the p.getunique is null, which only happens if:
    6) p.getUnique() throws a null if the player object is null at this point in the execution
    7) your getInt has a default value of 0 if the stringpath can not be found, so provided a null is not thrown while dereferencing objects to construct a string path, it wont matter if the path exists..
    oh, 8 - thats an i not a 1 .. your i-parameter passin might be null rather than 0, and the math is adding a value plus null... not very likely.

    So from that... either the player object or plugin object is null (and your use of static plugin definition probably takes care of the one case)
    Throw a debugging statement in with a null check for plugin and null check for player p in the code
    If neither of them throw a null then... that would be very surprising, so break up this complex statement into a few lines of code that make the two path strings separately, get the integer value separately, and then sets the config again, and see where the null is thrown. But it shouldn't come to that, you'll see either the plugin or player p is null when you hit this point... in which case, you then backtrack to see where to set it up for plugin, or double-check the calling functions to see why they are passing a null player object into this method. I quickly look through the code but cant see the calling location, you must have more code..

    The mortgage money is on:
    player p object is null
     
    TehCoderHD likes this.
Thread Status:
Not open for further replies.

Share This Page