Config list?

Discussion in 'Plugin Development' started by klosjaarrr, Oct 12, 2014.

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

    klosjaarrr

    Hey there, I was wondering how I can make a config file that looks like this:

    Code:
    Node1:
      - test1
      - test2
    Node2:
      - test1
      - test2
    And then get a list of Nodes and a list of the values inside a node. Any ideas? If possible, in a List or HashMap.
     
  2. HashMap<String, List<String>>
     
  3. Offline

    Unica

    klosjaarrr

    Code:java
    1. private void addToList(String listName, Object whatIwantToSave){ //Create a method
    2. List<String> curList = getConfig().getStringList(listName); //Create a variable of an existing list
    3. curList.add(whatIWantToSave); //Add new stuff you want to save to the list
    4. getConfig().set(listName, curList); //Update the current list by resetting it
    5. saveConfig(); //Save it
    6. }
    7.  
    8. //Example
    9. String jack; //few names here
    10. String james;
    11. String paul;
    12.  
    13. //Imagine you would want to save their names to a list called 'Names'
    14.  
    15. //Call the method
    16. addToList("Names", jack);
    17. addToList("Names", james);
    18. addToList("Names", paul);
    19.  
    20. //You could ofcourse use an array, or loop so you don't
    21. //have to copy every time
     
    klosjaarrr likes this.
  4. Offline

    CaptainUniverse

    do config.set(YourArea, Arrays.asList(Object1,Object2,Object3))
    to remove it set the area to null
    and to get the list do List(YourType) list = (Cast of YourType) config.getList(YourArea);
     
    klosjaarrr likes this.
Thread Status:
Not open for further replies.

Share This Page