Multiple values in a config

Discussion in 'Plugin Development' started by derin38, Jan 20, 2013.

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

    derin38

    Hi bukkit.

    Any way I could add multiple values of a config key?

    Like this:

    key:
    - value1
    - value2

    Instead of this:

    key1: value1
    key2: value2
     
  2. Offline

    Craftiii4

    Use a List

    Example:

    Code:java
    1. String[] dplist = { "7", "8", "9", "10", "11", "26", "36", "55", "74", "75", "83", "115", "117", "118", "119", "120" };
    2. getdroppartyConfig().addDefault("DropParty.BlockItemsId", Arrays.asList(dplist));


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  3. Offline

    danthonywalker

    config.get<String, Integer, Etc.>List()
     
  4. Offline

    chasechocolate

    What you want is a String list. This will return value1 and value2 (or as many values as you have) in a String[] format.
    Code:java
    1. getConfig().getStringList("key");

    You could put this in a for loop and loop through the values like so:
    Code:java
    1. for(String string : getConfig().getStringList("key")){
    2. //Code
    3. }
     
  5. Offline

    derin38

    chasechocolate

    Might work, I have some questions though.
    What if my code in the loop is to delete the value from the config?

    Code:java
    1. if (string == thevalueIwanttoremove){
    2. //How do I remove it then?
    3. }


    And how can I add a value?

    ... Please?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  6. Offline

    hockeygoalie5

    To set the value of a list in a config, create an Array, ArrayList, List, what ever with all the values currently in the list. Then, you can add/remove values from the list and use config.set("path.to.key", list);
     
  7. Offline

    derin38

    Is there no other way? I fear I would have to create too many lists.
     
  8. Offline

    hockeygoalie5

    Not that I have seen.
     
Thread Status:
Not open for further replies.

Share This Page