Solved Strange HashMap/YAML error.

Discussion in 'Plugin Development' started by pers2981, Apr 12, 2013.

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

    pers2981

    Hey there,

    While trying to make a simple leveling type plugin I've encountered a small bug. After spending countless hours trying to figure it out myself, I've given up. I come here, seeking guidance.

    First of all, here is the error itself.
    The Error (open)

    Code:
     
    2013-04-12 13:47:41 [INFO] [MinecraftLegend] Disabling MinecraftLegend v1.0
    2013-04-12 13:47:41 [INFO] 229 recipes
    2013-04-12 13:47:41 [INFO] [MinecraftLegend] Loading MinecraftLegend v1.0
    2013-04-12 13:47:41 [INFO] [MinecraftLegend] Enabling MinecraftLegend v1.0
    2013-04-12 13:47:41 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2013-04-12 13:47:41 [INFO] CONSOLE: Reload complete.
    2013-04-12 13:47:43 [SEVERE] Could not pass event EntityDeathEvent to MinecraftLegend v1.0
    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_R2.event.CraftEventFactory.callEntityDeathEvent(CraftEventFactory.java:318)
    at net.minecraft.server.v1_5_R2.EntityChicken.dropDeathLoot(EntityChicken.java:105)
    at net.minecraft.server.v1_5_R2.EntityLiving.die(EntityLiving.java:909)
    at net.minecraft.server.v1_5_R2.EntityLiving.damageEntity(EntityLiving.java:766)
    at net.minecraft.server.v1_5_R2.EntityAnimal.damageEntity(SourceFile:119)
    at net.minecraft.server.v1_5_R2.EntityHuman.attack(EntityHuman.java:854)
    at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:1102)
    at net.minecraft.server.v1_5_R2.Packet7UseEntity.handle(SourceFile:36)
    at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292)
    at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:110)
    at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:578)
    at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:225)
    at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:474)
    at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:407)
    at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
    at me.pers2981.MinecraftLegend.EntityLis.onMobDeath(EntityLis.java:40)
    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)
    ... 20 more
    Code:
    Caused by: java.lang.NullPointerException
    at me.pers2981.MinecraftLegend.EntityLis.onMobDeath(EntityLis.java:40)


    I've navigated to "EntityLis.java:40" to find the following.

    Code:
    Integer CurExp = plugin.PlayerExp.get(player.getName());
    This code creates a new variable that takes the value from a hashmap. This variable is the players current experience.

    I'm really not sure what's causing this error, any ideas?

    On a side note, while I was trying to debug the problem myself, I stumbled across the following.

    Main Listener Reg code (open)

    Code:
    pm.registerEvents(new EntityLis(null), this);
    

    EntityListener code (open)

    Code:
    @EventHandler
    public void onMobDeath(EntityDeathEvent event)
    {
    Entity entity = event.getEntity();
    if(entity instanceof LivingEntity) {
    LivingEntity living = (LivingEntity) entity;
    living.setCustomName(ChatColor.DARK_GREEN + "" + ChatColor.RED + "█████████");
    living.setCustomNameVisible(true);
    if (event.getEntity().getKiller() != null)
    {
    if (event.getEntity().getKiller() instanceof Player)
    {
    Player player = event.getEntity().getKiller();
    Integer CurExp = plugin.PlayerExp.get(player.getName());
    Integer MaxExp = plugin.PlayerLevel.get(player.getName()) * 100;
    Integer CurLvl = plugin.PlayerLevel.get(player.getName());
     
    CurExp = CurExp + 10;
     
    if (CurExp >= MaxExp)
    {
    plugin.PlayerLevel.remove(player.getName());
    plugin.PlayerExp.remove(player.getName());
    CurLvl = CurLvl + 1;
    CurExp = 0;
    plugin.PlayerLevel.put(player.getName(),CurExp);
    plugin.PlayerExp.put(player.getName(),CurExp);
     
    }
    }
    }
    }
    }
    
    Code:
    private MinecraftLegend plugin; 
     
    public EntityLis(MinecraftLegend plugin)
        {
            this.plugin = plugin;
            
        }
    

    I'm not sure if this would be some how causing the HashMap's to be 'null'?

    Any advice/guidance is greatly appreciated.

    Thanks
    Jacob
     
  2. Offline

    xmarinusx

    The error means that the HashMap does not contain the player.getName() key. Just use a != null check to fix it.

    EDIT:
    Why do you put this on null?
    pm.registerEvents(new EntityLis(null), this);

    You could better use
    pm.registerEvents(new EntityLis(this), this);
     
Thread Status:
Not open for further replies.

Share This Page