Solved Interleaved config entries

Discussion in 'Plugin Development' started by ScrouthTV, Mar 24, 2017.

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

    ScrouthTV

    I have a question about the config file.
    Is it possible to have an interleaved config file (see example)?
    Code:
    Trade:
      Input1:
        Material: ...
        Amount: ...
      Input2:
        Material: ...
        Amount: ...
      Output:
        Material: ...
        Amount: ...
    So what I mean, is having different categories with subcategories and entries.

    How do I write in those subcategories and read from them?

    btw: I think this is called interleaved, but I'm german, so sorry, if that's the wrong word...
     
  2. Offline

    Zombie_Striker

    @ScrouthTV
    Config#getConfigurationSection("Trade").getKeys(false) returns all the sub categories.
     
  3. Offline

    N00BHUN73R

    @ScrouthTV
    It's possible :). To get all of the main categories, in this case Input1, Input2 and Output, you'd use what ZombieStriker posted.
    To create such categories, you need to get the config, then it would be like this:
    PHP:
    getConfig().set("Trade.Input1.Material"Material.AIR);
    getConfig().set("Trade.Input2.Amount"2532);
    // And so on
    Then to get it, you'd do what Zombie posted like so:
    PHP:
    for(String s getConfig().getConfigurationSection("Trade").getKeys(false)) {
        
    Material material getConfig().get("Trade." ".Material"); // to get the material, but you'd have to use like Material.match
    }
    The above are just examples, the second one won't necessarily work but I hope you get the idea of what I'm going for.
     
    ScrouthTV likes this.
Thread Status:
Not open for further replies.

Share This Page