Configuration Section help

Discussion in 'Plugin Development' started by Jncwhite01, Mar 10, 2017.

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

    Jncwhite01

    Hello, currently making a plugin, and have not done much on configs in the past and got a problem here:

    My config.yml will look like this:

    Code:
    Showcases:
        Jncwhite:
          1:
            material: DIAMOND_PICKAXE
            amount: 1
            data: 0
            name: "&b&lDiamond Pickaxe"
            lore:
            - 'Lore 1'
            - '&cLore 2'
            enchantments:
            - 'DIG_SPEED,1'
            - 'DURABILITY,2'
            
    Was wondering how I could loop through each item (the config section 1 is the item) and then get each key and value?

    Thank you, also the current code I had was:

    Code:
    if(plugin.getConfig().isSet("Showcases." + player.getName()))
                    {
                        ConfigurationSection path = plugin.getConfig().getConfigurationSection("Showcases." + player.getName());
                       
                        for(String a : path.getKeys(true))
                        {
                           
                        }
                    }
    Pretty sure that does not work, but thats why im requesting help:)
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Jncwhite01 That would work though.
    a will be the 1 after Jncwhite
     
  3. Offline

    Jncwhite01

    Oh alright, so would i then need another for loop inside?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Jncwhite01 No.
    Inside the loop you use path.getConfigurationSection(a)
    Then you have the item related stuff (everything inside 1)
     
  5. Offline

    Jncwhite01

    Thank you for the reply, sorry for not being too good haha

    Would this work then?

    Code:
    if(plugin.getConfig().isSet("Showcases." + player.getName()))
                    {
                        ConfigurationSection path = plugin.getConfig().getConfigurationSection("Showcases." + player.getName());
                       
                        for(String a : path.getKeys(true))
                        {
                            path = path.getConfigurationSection(a);
                           
                            Material mat = Material.getMaterial(path.getString("material"));
                            int amount = path.getInt("amount");
                            double data = path.getDouble("data");
                            String name = path.getString("name");
                            ArrayList<String> lore = new ArrayList<String>();
                            ArrayList<String> enchants = new ArrayList<String>();
                            ArrayList<Integer> levels = new ArrayList<Integer>();
                           
                            for(String ench : path.getStringList("enchantments"))
                            {
                                String[] temp;
                                temp = ench.split(",");
                               
                                String enchantment = temp[0];
                                int level = Integer.parseInt(temp[1]);
                               
                                enchants.add(enchantment);
                                levels.add(level);
                            }
                        }
                    }
                    }
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Jncwhite01 Try it and find out ;)
    Best way to see if something is working.
     
  7. Offline

    Jncwhite01

    Yehh, I would haha, but cant right now, will have to check it in abit, thank you for the help though :)
     
Thread Status:
Not open for further replies.

Share This Page