Solved Issue with custom inventory.

Discussion in 'Plugin Development' started by Paxination, Jan 15, 2014.

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

    Paxination

    Code:
    quiver = Bukkit.createInventory(null, 18, "Quiver");
            etable = Bukkit.createInventory(null, InventoryType.ENCHANTING);
            if(playerfile.getConfig().contains("arrows")){
                if(playerfile.getConfig().contains("arrows.explosion")){
                    ItemStack arrow = new ItemStack(plugin.explosionarrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.explosion.amount"));
                    quiver.addItem(arrow);
                    
                }
                
                if(playerfile.getConfig().contains("arrows.poison")){
                    ItemStack arrow = new ItemStack(plugin.poisonarrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.poison.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.blindness")){
                    ItemStack arrow = new ItemStack(plugin.blindarrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.blindness.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.freeze")){
                    ItemStack arrow = new ItemStack(plugin.freezearrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.freeze.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.confusion")){
                    ItemStack arrow = new ItemStack(plugin.confusionarrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.confusion.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.sand")){
                    ItemStack arrow = new ItemStack(plugin.sandarrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.sand.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.web")){
                    ItemStack arrow = new ItemStack(plugin.webarrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.web.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.soul")){
                    ItemStack arrow = new ItemStack(plugin.soularrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.soul.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.fireworks")){
                    ItemStack arrow = new ItemStack(plugin.fireworksarrow.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.fireworks.amount"));
                    quiver.addItem(arrow);
                    
                }
    
                if(playerfile.getConfig().contains("arrows.lightning")){
                    ItemStack arrow = new ItemStack(plugin.lightningarrows.getResult());
                    arrow.setAmount(playerfile.getConfig().getInt("arrows.lightning.amount"));
                    quiver.addItem(arrow);
                    
                }
            }
    I can create an inventory, and i have a command that lets me open it. I have a method that saves it to disk and one that loads it back in. But my issue is if I have more than 9 items, it ONLY loads the last 9 items into it.

    I have checked my inventory 100's of times, I have 10 sets of arrows when I leave. But when i rejoin, i only have the top row filled. Just 9.

    Here is my save method.

    Code:
    public void saveArrows(){
            playerfile.getConfig().set("arrows", null);
            for(ItemStack arrow:quiver.getContents()){
                if (arrow!=null) {
                    if (arrow.getType().equals(Material.ARROW)) {
                        playerfile.getConfig().set("arrows." + arrow.getItemMeta().getLore().get(0).toLowerCase() + ".amount", arrow.getAmount());
                    }
                }
            }
        }
    I know the config has a getItemStack, but it doesnt reapply my custom enchantment to the arrows. It saves it, but doesnt apply the effect onloading.

    And even using the getItemStack, it still only fills the top row.

    TL;DR - Only top row is being filled. Wont additems to the next row in my inventory, just overwrites the top row.
     
  2. Paxination
    My best guess is that you are not adding the items to specific inventory spots and the items are overriding each other when added (idk if that makes sense or not). Maybe try assigning each item to a specific spot in the inventory and see what happens
     
  3. Offline

    Paxination

    I get what your saying and I was thinking the same thing, but I figured the additem method just tacked it on to the end. Would have never thought that I would have to manually assign spots.

    I guess I could make a method that would find a free spot for me.

    Another quirk I noticed lately, is that getContents() apparently returns a FULL list of every slot. Whether or not it has something in it. So if you have an empty slot. It will return null for that one. Which dont make sense to me with a name called "GETCONTENTS"
    any ways, i'll give that a try! Just wanted to make sure it wasnt my code first.

    The Gaming Grunts

    Turns out it is my code. And addItem(ItemStack) works fine. The 1 item that wasnt getting loaded was because at one point I changed the lore name on it to identify it, and didnt change it in another place of my code. So it was saving the wrong lore to disk.

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

    Paxination

Thread Status:
Not open for further replies.

Share This Page