Solved Generating inv... glitchyy someone see what im doing wrong...

Discussion in 'Plugin Development' started by EnchantedMiners, Nov 26, 2015.

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

    EnchantedMiners

    Hello guys so my problem is the following:
    here is my code:

    Code:
        public Inventory generateHousesMenu(){
            File folder = new File("plugins/Houses");
            File[] listOfFiles = folder.listFiles();
    
            List<String> housenames = new ArrayList<>();
           
            for (int i = 0; i < listOfFiles.length; i++) {
                if (listOfFiles[i].isFile()) {
                    if(listOfFiles[1].getName().endsWith(".schematic")){
                        housenames.add(listOfFiles[i].getName());
                    } else {
                        housenames.add("Error while loading house "+listOfFiles[i].getName());
                    }
                }
            }
           
            Inventory inv = Bukkit.createInventory(null, getGuiSlotsNumber(housenames.size()-1), "§f§lSelect a house");
            inv.clear();
           
            for(String house : housenames){
                ItemStack is = new ItemStack(Material.CHEST);
                ItemMeta im = is.getItemMeta();
                im.setDisplayName(house.replace(".schematic", ""));
               
                List<String> lore = new ArrayList<>();
                lore.add("");
                lore.add("§aClick to start building this house!");
                im.setLore(lore);
                is.setItemMeta(im);
               
                for(int i = 0; i < housenames.size(); i++){
                    inv.setItem(i, is);   
                }
            }
           
            return inv;
        }
    So there shouldn't be any problem generating the items inside the inventory.... but i get this....
    [​IMG]
    AND I HAVE THIS ON THE FOLDER....
    [​IMG]
    Makes no sense to me please someone help me spot my silliness....
     
  2. Offline

    teej107

  3. Offline

    Scimiguy

    Your second forloop is looping over all 4 slots and placing your current itemstack inside it.
    You either need to store the stacks as variables outside the loop and move your for loop outside of it, or you need to keep a counter variable and place the current item in that slot each time you loop
     
  4. Offline

    teej107

    or
    Trust me. It's a stupid mistake!
     
    EnchantedMiners likes this.
  5. Offline

    EnchantedMiners

    @teej107 ikkk i tried switching the loops then i tried switching the position of the loops no luck same result... i ma mess with the code and see what works....

    Im going to try storing the itemstacks with the names and all then loop thru them and add them to the inv that should work...

    Is rubberduck debugging a software or a wiki guide ?

    EDIT: Nvm thats a technic LMFAO ... nice one doe it helps but omg i tried sooooo much things...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 26, 2017
  6. Offline

    teej107

    Have you tried
    ?
     
  7. Offline

    Mrs. bwfctower

  8. Offline

    teej107

    Yes it does help. You'll be surprised. Read the wiki to understand more about it.
     
  9. Offline

    EnchantedMiners

    @teej107 @Mrs. bwfctower @Scimiguy Ok so this code worked perfectly....
    I didn't had to use the for loop for the slot
    Code:
        public Inventory generateHousesMenu(){
            File folder = new File("plugins/Houses");
            File[] listOfFiles = folder.listFiles();
    
            List<String> housenames = new ArrayList<>();
          
            for (int i = 0; i < listOfFiles.length; i++) {
                if (listOfFiles[i].isFile()) {
                    if(listOfFiles[1].getName().endsWith(".schematic")){
                        housenames.add(listOfFiles[i].getName());
                    } else {
                        housenames.add("Error while loading house "+listOfFiles[i].getName());
                    }
                }
            }
          
            Inventory inv = Bukkit.createInventory(null, getGuiSlotsNumber(housenames.size()-1), "§f§lSelect a house");
            inv.clear();
          
            int slot = 0;
          
            for(String house : housenames){
                ItemStack is = new ItemStack(Material.CHEST);
                ItemMeta im = is.getItemMeta();
                im.setDisplayName(house.replace(".schematic", ""));
              
                List<String> lore = new ArrayList<>();
                lore.add("");
                lore.add("§aClick to start building this house!");
                im.setLore(lore);
                is.setItemMeta(im);
              
                inv.setItem(slot, is);
                slot = slot+1;
            }
          
            return inv;
        }
    Thanks for the help.
     
    teej107 likes this.
  10. Offline

    Zombie_Striker

    Mark as solved if solved.
     
Thread Status:
Not open for further replies.

Share This Page