Loop on Gui help(quick question)

Discussion in 'Spigot Plugin Development' started by luigieai, Jan 17, 2015.

  1. Hello guys
    This is a quick question, im creating a GUI system for my plugin, and i need some for help(i forgot some things in BukkitApi), and i have a config, i used this method to get thte kits to config:
    Code (Text):
            ArrayList<String> kits = new ArrayList<String>();
            Inventory shop = Bukkit.createInventory(null, 54, ChatColor.BOLD+""+ChatColor.GREEN+"Selecione seu kit");
            for(String s : SettingsManager.getKits().getH().getKeys(false)) {
                kits.add(s);
                if(kits.size() > 54){
                    System.out.println(ChatColor.RED+"Deu ERRO");
                    p.sendMessage(Main.prefix+ChatColor.RED+"Não foi possivel abrir shop, ha kits demais, contate o administrador");
                    kits.clear();
                    return;
                }
            }
    And im using this to set all kits (now in the arraylist) to inventory

    Code (Text):
            for(int i=0;i<=kits.size();i++){  
            shop.setItem(i,Kits.getKit().GuiItem(kits.get(i)));
            }
    But i dont know if the kits.get(i) will work in all inventory with their respectives kits, the GuitItem method:
    Code (Text):
        public ItemStack GuiItem(String kit){
            return new ItemBuilder((Material) SettingsManager.getKits().get(kit+".Icone")).name((String) SettingsManager.getKits().get(kit+".Nome"))
                    .lore((String) SettingsManager.getKits().get(kit+".Lore"))
                    .build();
        }
     
  2. Can you explain further? I'm a bit confused.
     
  3. My english is poor, i know.
    In my plugin, the kits isn't predefined, they are created by a command, /createkit [Name]. When the command is executed, in my kits.yml create a section with the kit name:
    PHP:
    [KitName]:
    Armor:
    Itens:
    GuiIcon:
    GuiLore:
    When my minigame is in a lobby stage, the player will receive a Kit Selector item(opens a GUI with their kits) and a Shop item(opens the shop GUI), im creating the shop GUI, that identify all kits in config, my code is like that:
    Code (Text):
        public void abrirSelector(Player p){
            ArrayList<String> kits = new ArrayList<String>();//ArrayList to store kits names
            Inventory shop = Bukkit.createInventory(null, 54, ChatColor.BOLD+""+ChatColor.GREEN+"Selecione seu kit");//create the GUI
            for(String s : SettingsManager.getKits().getH().getKeys(false)) {//I use this to pick all the kits names from my config
                kits.add(s);//add the names to arraylist
                if(kits.size() > 54){//check if the size is greater than the inventory slots
                    System.out.println(ChatColor.RED+"Deu ERRO");//If yes, print kida of error on console
                    p.sendMessage(Main.prefix+ChatColor.RED+"Não foi possivel abrir shop, ha kits demais, contate o administrador");
                    kits.clear();//Avoiding bugs
                    return;
                }
            }
            /*
             * Now this is my problem, i already know the kits will not "break" the GUI, but how i can set the kits itens(already specified on config)
             * in my inventory, im using this, but i think im doing wrong
             */
            for(int i=0;i<=kits.size();i++){
            shop.setItem(i,Kits.getKit().GuiItem(kits.get(i)));
            /*
             * Kits.getKit.GuiItem(); is the my method to pick the item for the gui in my config file
             * here is the method:
             *
             *
             *     public ItemStack GuiItem(String kit){
            return new ItemBuilder((Material) SettingsManager.getKits().get(kit+".Icone")).name((String) SettingsManager.getKits().get(kit+".Nome"))
                    .lore((String) SettingsManager.getKits().get(kit+".Lore"))
                    .build();
        }
             */
            }
        }
     
  4. Sorry, im really need help.
    BUMP
     
  5. Senmori

    Senmori Retired Resource Staff
    Retired Patron

    If you're wondering if it works or not then it looks fine. Are you getting any errors from your IDE? Have you compiled and tried it yet?