Solved Error When making Custom Inventory

Discussion in 'Plugin Help/Development/Requests' started by Guitarax, Jan 12, 2015.

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

    Guitarax

    I have inventory menus that both do and do not exceed 9. The ones that do not exceed 9 run fine, the ones that do only go up to 18. I am using chest inventory type but have tried others and all return this same error.

    here is the code it's pointing to...


    Code:
        public static void mobdrops(){
            ArrayList<Double> buy = new ArrayList<Double>();
            ArrayList<Double> sell = new ArrayList<Double>();
            ArrayList<ItemStack> material = new ArrayList<ItemStack>();
            material.add(new ItemStack(Material.BONE,1));
            material.add(new ItemStack(Material.ARROW,1));
            material.add(new ItemStack(Material.ROTTEN_FLESH,1));
            material.add(new ItemStack(Material.SULPHUR,1));
            material.add(new ItemStack(Material.SPIDER_EYE,1));
            material.add(new ItemStack(Material.STRING,1));
            material.add(new ItemStack(Material.ENDER_PEARL,1));
            material.add(new ItemStack(Material.SLIME_BALL,1));
            material.add(new ItemStack(Material.LEATHER,1));
            material.add(new ItemStack(Material.FEATHER,1));
            material.add(new ItemStack(Material.EGG,1));
            material.add(new ItemStack(Material.STICK,1));
            material.add(new ItemStack(Material.INK_SACK,1));
            material.add(new ItemStack(Material.GOLD_NUGGET,1));
            material.add(new ItemStack(Material.ENDER_CHEST,1));
            material.add(new ItemStack(Material.ENDER_CHEST,1));
            material.add(new ItemStack(Material.ENDER_CHEST,1));
            material.add(new ItemStack(Material.ENDER_CHEST,1));
            buy.add(15.00);  sell.add(5.25);
            buy.add(10.00);  sell.add(4.50);
            buy.add(5.00);  sell.add(1.00);
            buy.add(21.00);  sell.add(8.50);
            buy.add(15.00);  sell.add(5.75);
            buy.add(15.00);  sell.add(8.00);
            buy.add(42.00);  sell.add(20.25);
            buy.add(35.00);   sell.add(5.00);
            buy.add(5.00);   sell.add(0.00);
            buy.add(5.00);   sell.add(0.00);
            buy.add(5.00);   sell.add(0.00);
            buy.add(5.00);   sell.add(0.00);
            buy.add(5.00);   sell.add(0.00);
            buy.add(10.00);   sell.add(2.00);
            List<String> lore = new ArrayList<String>();
            Player player = main.sp_player;
            Inventory inv = Bukkit.createInventory(null, InventoryType.PLAYER);
            for(int i = 0; i <= 17; i++){
                if(i < 13){
                    lore.add("$" + buy.get(i) + " BUY (Left Click) / (Right Click) SELL $" + sell.get(i));
                }
                else{
                    lore.add("[OPEN SLOT]");
                }
                ItemStack stack = material.get(i);
                ItemMeta meta = stack.getItemMeta();
                meta.setLore(lore);
                if(i > 12){
                    meta.setDisplayName("[OPEN SLOT]");
                }
                lore.remove(0);
                inv.setItem(i, stack);
            }
            Inventory pinv = Bukkit.createInventory(null, 18, ChatColor.RED + "MobDrops");
            pinv.setContents(inv.getContents());                          //LINE 248 in entire class
            player.openInventory(pinv);       
            drop_buy = buy;
            drop_sell = sell;
        }
    NOTE: I've commented in where 248 is.

    Notice where the Inventory is set the size is set to 18 yet the error is still considering it to be greater than that. Also, this isn't a case where it would be 1 less than 18 such as with an array as Bukkit requires inventories to be multiples of 9.
     
  2. Offline

    16davidjm6

    a player inventory is 36 slots, even if there are less than 36 items in it.

    You are trying to cram 36 slots worth of inventory space into an inventory that only has 18 slots.
     
  3. Offline

    Guitarax

    This is right, didnt know the inventory had to be defined as the full number to be accepted, pretty much just set my type to chest and set the final inventory to 27 instead of 18, thanks.
     
Thread Status:
Not open for further replies.

Share This Page