strange npe!

Discussion in 'Plugin Development' started by the_merciless, Jun 15, 2013.

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

    the_merciless

    I have this method....

    Code:
    @SuppressWarnings("deprecation")
        public void addclassitems(String pname) {
           
            User user = playerdata.get(pname);
            Player p = Bukkit.getPlayer(pname);
     
            Bukkit.broadcastMessage("pname = " + pname);
            Bukkit.broadcastMessage("user = " + user);
            Bukkit.broadcastMessage("Player = " + p);
     
            if (user.getClassname().equalsIgnoreCase("creeper")) {        
                p.getInventory().setHelmet(new ItemStack(Material.SKULL_ITEM, 1, (short) 4));
                p.updateInventory();
            }   
        }
    when testing pname returns my name, but Player returns null. No idea why though. Any help?
     
  2. Offline

    Minnymin3

    What exactly is the problem? Which line does the stacktrace say its on? It could be because the pname is the name of a player that is not online.
     
  3. Offline

    the_merciless

    I'm testing with myself, so I am definately online. The problem is that the player is returning null (npe is on the line p.getInventory....). I have it working now by passing a player in, instead of the players name. I'm calling this method on a player respawn event, so I guess during the event the player is not listed as online, hence why it was returning null;
     
Thread Status:
Not open for further replies.

Share This Page