Solved Config Interface: how to craete an array?

Discussion in 'Plugin Development' started by UltraMC, Jan 18, 2014.

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

    UltraMC

    How to produce array fron config interface?

    I can craete single or nested values with:
    Code:java
    1. FileConfiguration config = getConfig();
    2.  
    3. config.addDefault("singleValue", Boolean.valueOf(true)); // single
    4. config.addDefault("nested.value", Boolean.valueOf(true)); // nested


    Like:
    Code:java
    1. singleValue: true
    2. nested:
    3. value: true


    But how to get something like this:
    Code:java
    1. parent:
    2. - element1
    3. - element2


    or:
    Code:java
    1. parent: []


    PS YAML syntax tag would be handy
     
  2. Offline

    Yonas

    Code:
            for(String s : config.getConfigurationSection("parent").getKeys(false)) {
             
            }
    
    or
    Code:
    Set<String> theList = config.getConfigurationSection("parent").getKeys(false);
    Object[] yourArray = theList.toArray();
    
     
  3. Offline

    Henzz

    UltraMC
    forgot to tahg.
    Also isn't it.

    Code:
    private List<String> parentElements;
     
    // Initialise in onEnable
    parentElements = getConfig().getStringList("parent");
     
  4. Offline

    Avery246813579

    UltraMC
    He is asking how he would make one, not get it.

    To create one use:
    Code:java
    1. /** Creates the List **/
    2. List<String> list = new ArrayList<String>();
    3. /** This is how you add something to the list **/
    4. list.add("X");
    5. /** Setting the list in the config **/
    6. getConfig().set("list", list);


    To get a array list from the config do:
    Code:java
    1. /** Creates a list **/
    2. List<String> list;
    3. /** Sets the list to the list in the config **/
    4. list = getConfig().getStringList("list");


    If you wanted the List to be an integer, just change the List<String> to List<Integer>, then change getStringList("list") to getIntegerList("list").
     
    UltraMC likes this.
  5. Offline

    UltraMC

    Thanks, that's what I needed.


    That representates level of discussion at this forums btw.
     
Thread Status:
Not open for further replies.

Share This Page