Solved event not removing item from hand...

Discussion in 'Plugin Development' started by vhbob, Feb 6, 2016.

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

    vhbob

    hello, this event does everything its supposed to except removing the item from the players hand, any ideas?
    Code:
    public void takei(Player p){
            p.getItemInHand().setType(Material.AIR);
        }
       
        @EventHandler
        public void invC(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            if (e.getInventory().getName().equalsIgnoreCase("Use This Item?")) {
                ItemMeta cm = e.getCurrentItem().getItemMeta();
                if (cm.getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Yes!")) {
                    p.sendMessage("ss");
                    getConfig().set(p.getName() + ".WaterBreathing", true);
                    saveConfig();
                    p.sendMessage(ChatColor.AQUA + "Water Breathing Aquired!");
                    p.closeInventory();
                    takei(p);
                    e.setCancelled(true);
                }
                if (cm.getDisplayName().equalsIgnoreCase(ChatColor.RED + "No!")) {
                    p.sendMessage("s");
                    e.setCancelled(true);
                    p.closeInventory();
                }
            }
        }
    nvm fixed it, i had to change it to
    Code:
    p.setItemInHand(null);
    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Feb 6, 2016
  2. Offline

    [ HashMap ]

    You can do: player.getItemInHand().setType(Material.AIR);
     
Thread Status:
Not open for further replies.

Share This Page