Solved Private Inventory refuses to open

Discussion in 'Plugin Development' started by kampai, Jul 13, 2016.

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

    kampai

    Hello I'm not sure why, but when I try to open this inventory it decides not to work ):
    Code:
        Inventory getKitsInventory(Player player){
            Inventory kits = kitsinventory.get(player.getName());
             
            if(kits == null){
                kits = Bukkit.createInventory(null, 9, player.getName() + "'s virtual chest");
                kits.addItem(new ItemStack(Material.APPLE));
               
                int listsize = config.get(player).getList("kits").size();
                ItemStack kitblock = new ItemStack(Material.MAGMA_CREAM, 1);
                ItemMeta kitblockim = kitblock.getItemMeta();
    
                for (int i = 0; i < listsize; i++) {
    
                    String kitname = config.get(player).getStringList("kits").get(i);
                    kitblockim.setDisplayName(ChatColor.GREEN + kitname + "");
                    ArrayList<String> lores = new ArrayList<String>();
                    lores.add(ChatColor.GRAY + "Click to use the kit editor");
                    lores.add(ChatColor.GRAY + "You used " + ChatColor.GREEN + "0.0/25.0" + ChatColor.GRAY + " points");
                    kitblockim.setLore(lores);
                    kitblock.setItemMeta(kitblockim);
    
                    kits.setItem(i, kitblock);
    
               
    
                ItemStack pane = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 14);
                ItemMeta paneim = pane.getItemMeta();
                paneim.setDisplayName(ChatColor.RED + "#");
                pane.setItemMeta(paneim);
    
                while (!(kits.firstEmpty() == -1)) {
                    kits.setItem(kits.firstEmpty(), pane);
                }
                kitsinventory.put(player.getName(), kits);
                player.openInventory(kits);
                }
           
        }         
            return kits;
               
        }
    Yes I am remembering to remove them from the hashmap, since if I wasn't it would open once and not again, but it does not open at all. Also to note the event that is opening the chest is fine because I made it play a sound before opening it and it actually does play the sound just doesnt open the chest.
     
  2. Offline

    ipodtouch0218

    Your player.openInventory(kits); is inside of the for loop... not sure why.
     
  3. Offline

    kampai

    @ipodtouch0218
    Didn't notice that, I fixed that but it still doesn't work and I dont know why, I tried the same code, but instead of adding all the stuff I need i only added an apple which worked. This should also work because I have used it when a set inventory and it did add everything to it

    Sorry it works on my local server but not my public one, its being stupid smh

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
Thread Status:
Not open for further replies.

Share This Page