Solved Nullpointer when clicking outside of inventory

Discussion in 'Plugin Development' started by iBecameALoaf, Apr 1, 2014.

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

    iBecameALoaf

    I'm getting this really annoying nullpointer on this line:

    Code:
    if(event.getCurrentItem().getType() == Material.IRON_SWORD && event.getCurrentItem().getType() != null) {
    Full event code:

    Code:
        @EventHandler
        public void inventory(InventoryClickEvent event) {
            if(event.getInventory().getName() == "Minigames!") {
                event.setCancelled(true);
                Player player = (Player) event.getWhoClicked();
     
                if(event.getCurrentItem().getType() == Material.IRON_SWORD && event.getCurrentItem().getType() != null) {
                    plugin.getServer().dispatchCommand(player, "go " + plugin.getConfig().getString("worlds.SG"));
                    player.getWorld().playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 5, 5);
                    player.sendMessage(ChatColor.GREEN + "Teleported to Survival Games!");
                }
            }
        }
    Any ideas how to fix this?

    EDIT: Fixed with this:
    Code:
    if(event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR)
    Nullpointer: http://pastebin.com/yUAqRiHe
     
    xenon05 and bballheat like this.
Thread Status:
Not open for further replies.

Share This Page