Making a loop through a string list

Discussion in 'Plugin Development' started by wydgabriel, Jul 10, 2016.

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

    wydgabriel

    Hello guys, I'm trying to make a loop through my config to add those items to inventory.

    Here's the config:


    Arenas_GUI:
    - Item1:
    Material: 267
    Nome: '&dArena 1'
    Lore:
    - '&7Clique para teleportar'
    - Item2:
    Material: 267
    Nome: '&dArena 2'
    Lore:
    - '&7Clique para teleportar'

    How do I add those items into a inventory? Or create a ItemStack collection with those items and respective itemmetas?

    Thanks
     
  2. Offline

    CruzAPI

    Make your config like this:
    Code:
    Arenas_GUI:
      list:
      - Item1
      - Item2
      Item1:
        Material: 267
        Nome: '&dArena 1'
        Lore:
        - '&7Clique para teleportar'
      Item2:
        Material: 267
        Nome: '&dArena 2'
        Lore:
        - '&7Clique para teleportar'
    Eventually, to get the items through the for loop:
    Code:
    for(String string : config.getStringList("Arenas_GUI.list"))
    {
      int ID = config.getInt("Arenas_GUI." + string + ".Material");
      String name = config.getString("Arenas_GUI." + string + ".Nome");
      ArrayList<String> lore = (ArrayList<String>) config.getStringList("Arenas_GUI." + string + ".Lore");
    }
     
    Last edited: Jul 14, 2016
  3. Offline

    mine-care

    @CruzAPI First of all, please post in English which is the language of these forums and is understood by most members, and secondly please do not spoonfeed :)
     
  4. Offline

    wydgabriel

    Code:
      
      for(String name : plugin.getConfig().getStringList("Arenas_GUI.list"))
    {
      int material = plugin.getConfig().getInt("Arenas_GUI." + name + ".Material");
      String display = formatMessage(plugin.getConfig().getString(("Arenas_GUI." + name + ".Nome")));
      ItemStack item = new ItemStack(material, 1);
      ItemMeta meta = item.getItemMeta();
      meta.setDisplayName(display);
     ArrayList<String>lore = (ArrayList<String>) plugin.getConfig().getStringList("Arenas_GUI." + name + ".Lore");
       for (int i = 0; i < lore.size(); i++) {
      String linha = formatMessage(lore.get(i));
      meta.getLore().add(linha);   
      }
     item.setItemMeta(meta);
     inv.addItem(item);
    }
    Doesnt work.. dont get me any error, but the inventory continues empty
     
  5. Offline

    mine-care

Thread Status:
Not open for further replies.

Share This Page