Development Assistance Reading config files

Discussion in 'Plugin Help/Development/Requests' started by PaperJump, May 21, 2015.

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

    PaperJump

    Code:
    x:
      boolean: 1
    How can the values of x.boolean in a config.yml be read where the user can specify an unlimited amount of x's?

    For example, how can I read the PRISMARINE.boolean:
    Code:
    STONE
      boolean: 1
    PRISMARINE
      boolean: 0
    if the user can specify 'STONE', 'PRISMARINE' and an unlimited number of blocks?

    I'm new to plugin development... and I've tried decompiling plugins and reading tutorials with not much luck. Any help would be greatly appreciated!
     
    Last edited: May 21, 2015
  2. Offline

    pie_flavor

    @PaperJump Here is a sample config that will work with my example:
    Code:
    a:
      b:
        c: '¤'
      d:
        c: 'µ'
    c is the variable, b and d are the identifiers.
    They are in the section a.
    Code:
    ConfigurationSection section = getConfig().getConfigurationSection("a");
    //you don't need that if it's in the root, as opposed to under a section (in this case a)
    HashMap<String, String> map = new HashMap<String, String>();
    //you can store them however you like, maps are easy
    for (String key : section.getKeys(false)) {
    //the false means don't search deep (so only give 'b' and 'd', not 'c'
        map.put(key, section.getString(key+".c"));
    }
    Random additional fact for when you find yourself not needing a label - this is perfectly valid:
    Code:
    a:
    - b:
      c:
      d:
    - b:
      c:
      d:
    In this case, you would use get("a"), and cast it to List<LinkedHashMap>.
     
Thread Status:
Not open for further replies.

Share This Page