FileConfiguration - get a list of main paths.

Discussion in 'Plugin Development' started by alex123099, Jul 23, 2013.

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

    alex123099

    I have a .yml file which contains a bunch of items and their properties.
    for example:
    Code:
    cookie:
      price: 5
      desc: this is a cookie
    shovel:
      price:2
      desc: get this awesome shovel
    rankup:
      price: 50
      desc: raise your rank
    
    What I want to do, is get a list which will contain all the main paths, meaning ->
    {"cookie", "shovel", "rankup"}

    How would I be going on doing that?
     
  2. Offline

    MistPhizzle

    Code:java
    1. Set<String> items = plugin.getConfig().getConfigurationSection("").getKeys(false);


    That should do the trick, returns everything in a set. You can then send the player the set using items.toString(), or you can iterate through the set.
     
  3. Offline

    seemethere


    You wouldn't even need the getConfigurationSection("") bit.

    It works fine just as:

    Code:java
    1. Set<String> items = plugin.getConfig().getKeys(false);
     
  4. Offline

    alex123099

    Thank you, and how I would go with changing the path names?
    What I mean is if for example I have:
    Code:
    cookie:
      price: 5
      desc: this is a cookie
    
    and I now want it to be:
    Code:
    cookiessss:
      price: 5
      desc: this is a cookie
    
    How would I do that?
     
  5. Offline

    blablubbabc

    //get the values of the old cookie:
    ConfigurationSection cookie = getConfig().getSection("cookie");
    if (cookie != null) {
    int price = cookie.getInt("price");
    String desc = cookie.getString("desc");

    // remove the old section:
    getConfig().set("cookie", null);

    // add new section and add previous cookie values:
    ConfigurationSection cookiessss = getConfig().createSection("cookiessss");
    cookiessss.set("price", price);
    cookiessss.set("desc", desc);
    }
     
  6. Offline

    alex123099

    There is no getSection method

    Edit: getConfigurationSection -> found it
     
Thread Status:
Not open for further replies.

Share This Page