GUI Inventory help

Discussion in 'Plugin Development' started by Jackson12, Jun 10, 2015.

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

    Jackson12

    Hey, I have this GUI-Kit plugin that i am creating, and when i type /kit it opens the menu, but when i get out of the menu and try and shift click into my inventory it puts the item back where it was. And i can't grab items out of my inventory either. Thanks for any help.
    Code:
        private void openGUI ( Player player) {
            Inventory i = Bukkit.createInventory(null, 9, ChatColor.AQUA + "Kits");
          
            ItemStack Heavy = new ItemStack(Material.DIAMOND_CHESTPLATE);
            ItemMeta Heavymeta = Heavy.getItemMeta();
          
            Heavymeta.setDisplayName(ChatColor.AQUA + "Heavy");
            Heavy.setItemMeta(Heavymeta);
          
            i.setItem(1, Heavy);
          
            player.openInventory(i);  
        }
      
        @EventHandler
        public void onInventoryClickEvent(InventoryClickEvent e) {
            if(ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("Heavy"))
            return;
            Player player = (Player) e.getWhoClicked();
            e.setCancelled(true);
          
            if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()) {
                player.closeInventory();
                return;
            }
            switch (e.getCurrentItem().getType()) {
            case DIAMOND_CHESTPLATE:
                player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
                player.sendMessage(ChatColor.GREEN + "You have been given kit " + ChatColor.BLUE + "Heavy");
                break;
            default:
                player.closeInventory();
                break;
            }
        }
    Please help!

    Idk what to do

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

    seanliam2000

    I am decent with inventory menus and can probably help but I am confused as to what isn't working
     
  3. Offline

    CONTREKEE

    .
     
    Last edited: Jun 10, 2015
  4. Offline

    caderape

    @Jackson12
    1. if(ChatColor.stripColor(e.getInventory().getName()).equalsIgnoreCase("Heavy"))
    2. return;
    3. e.setCancelled(true);
    You cancel everyInventoryCLick except the one in your created inventory
     
  5. Offline

    Jackson12

    Ok i fixed it, I changed e.setCancelled(true); to e.setCancelled(false);
     
Thread Status:
Not open for further replies.

Share This Page