Solved Inventory Help

Discussion in 'Spigot Plugin Development' started by JustCedric, Jun 14, 2016.

  1. Hi guys,

    I'm working on a KitPvP plugin right now and I have a problem. When you open the Kit Selector and choose the kit in slot 5 (Archer kit right now) you dont get your helmet put on and if you open your inventory it will just be on your mouse icon (The kits work good because if I switch the slots for example Archer to slot 3 the helmet is on your helmet slot)

    [​IMG]
    URL to image

    CODE:
    Inventory
    Code (Text):
    public static Inventory getKitSelector(Player p) {


            /*
             *  0  1  2  3  4  5  6  7  8
             *  9 10 11 12 13 14 15 16 17
             */
       
            Inventory inv = Bukkit.createInventory(null, 18, "Kit Selector");
       
            ItemStack knight = new ItemStack(Material.IRON_SWORD, 1);
            ItemMeta knightMeta = knight.getItemMeta();
            knightMeta.setDisplayName("§cKnight");
            knight.setItemMeta(knightMeta);
       
            ItemStack tank = new ItemStack(Material.IRON_CHESTPLATE, 1);
            ItemMeta tankMeta = tank.getItemMeta();
            tankMeta.setDisplayName("§cTank");
            tank.setItemMeta(tankMeta);
       
            ItemStack archer = new ItemStack(Material.BOW, 1);
            ItemMeta archerMeta = archer.getItemMeta();
            archerMeta.setDisplayName("§cArcher");
            archer.setItemMeta(archerMeta);
       
            inv.setItem(3, knight);
            inv.setItem(4, tank);
            inv.setItem(5, archer);
       
            return inv;
        }
    InvClickEvent
    Code (Text):
        @EventHandler

        public void onClick(InventoryClickEvent e) {
            if (!e.getClickedInventory().getName().equals("Kit Selector")) return;
            Player p = (Player) e.getWhoClicked();
            String prefix = "§f[§c§lKitPvP§f] ";
       
            if (e.getCurrentItem() == null) return;
            if (e.getCurrentItem().getItemMeta() == null) return;
            if (e.getCurrentItem().getItemMeta().getDisplayName() == null) return;
            if (e.getCurrentItem().getType() == Material.AIR) return;
            p.closeInventory();
            String kit = e.getCurrentItem().getItemMeta().getDisplayName();
            p.sendMessage(prefix + "§fYou have chosen the " + kit + "§f kit!");
            if (e.getCurrentItem().getItemMeta().getDisplayName().equals("§cKnight")) {
                KitManager.giveSwordsman(p);
                return;
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().equals("§cTank")) {
                KitManager.giveTank(p);
                return;
            } else if (e.getCurrentItem().getItemMeta().getDisplayName().equals("§cArcher")) {
                KitManager.giveArcher(p);
                return;
            }
        }
     
    #1 JustCedric, Jun 14, 2016
    Last edited: Jun 14, 2016
  2. Cancel the event once you have determined that they have selected a kit.
     
  3. Thank you that works ;)