I have some problems with my kits plugin for Bukkit and Spigot. When I use the command /kits only an empty inventory opens. Here's my code:
for (int i = 0; i<main.cfg.getConfigurationSection("kits").getKeys(false).size();i++) {
String s = (String) main.cfg.getConfigurationSection("kits").getKeys(false).toArray()[i];
ItemStack is = new ItemStack(Material.valueOf(main.cfg.getString("kits." + s + ".mat")));
ItemMeta im = is.getItemMeta();
im.setDisplayName(s);
is.setItemMeta(im);
cont.add(is);
}
the item stack is valid, but when I do kits.add (is) the item doesn't get added to the inventory.
Bukkit.createInventory(null,size,"Kits");
and it shows up correctly((Player)sender).openInventory(kits);
You see cont.add(is)
in the code, because I've tried to make a list of ItemStack (cont) and then in another for loop add all items to the inventory, but that shouldn't make a difference.
I found a solution for this problem. It was because I calculated the size of the inventory depending on how many kits there are. Today I wondered why I had 3 lines in the inventory and just 1 kit. that should only make 1 line. then I set it to 54 items so 6 lines as inventory size and it worked! Solution: make sure that you're creating at least 3 lines in your inventory, then it should work.