Add children to config

Discussion in 'Plugin Development' started by To175, Nov 13, 2014.

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

    To175

    Hi, I didn't get it, how to do please ?
    I have that in config.yml (1st) and need to have that (2nd)
    Code:java
    1. Banned:
    2. - 'player1'
    3. - 'player2'

    Code:java
    1. Banned:
    2. - 'player1'
    3. - 'player2'
    4. - 'player3'
    5. - 'player4'


    And I don't know how to read such list :eek:
    Have I to do setString("Banned").getKey(true) ?
    And so what to do after that ?

    Thanks
     
  2. Offline

    Monkey_Swag

  3. Offline

    To175

    Monkey_Swag Thanks,
    But how to add elements please ?
     
  4. Offline

    Skionz

    list.add(objector something);
     
  5. Offline

    To175

    Skionz I don't understand and can't fin the difference between the getConfig.getString("NormalPath.with.children")
    And the list :(
    Have I to do that ?
    Code:java
    1. getConfig().addStringList("Path.To.Your.List");

    With "addStringList" ?
     
  6. Offline

    Skionz

    To175 getString returns a String and getList returns a list. I'm not really sure what your asking.
     
  7. Offline

    Monkey_Swag

    To175 Taken from the configuration API reference:
    Code:java
    1. // Setting a List of Strings
    2. // The List of Strings is first defined in this array
    3. List<String> listOfStrings = Arrays.asList("Hello World", "Welcome to Bukkit", "Have a Good Day!");
    4. this.getConfig().set("path.to.list", listOfStrings);
     
  8. Offline

    To175

    Monkey_Swag Thanks but I need to add elements, I don't want to set it.
    I have a huge list and I need to add elements.
     
  9. To175 Get the current elements, add to the list, and then set.
     
  10. Offline

    To175

    AdamQpzm Fortunately I said
     
  11. To175 ...So? Not sure how that changes anything.
     
  12. Offline

    To175

    Ok, thanks AdamQpzm so I have to do :
    Code:java
    1. List<String> list = getConfig().getList("path.to.list");
    2. list.add("to175");

    ?
     
  13. To175 And then the set method, yes. :)
     
    To175 likes this.
  14. Offline

    Gnat008

    To175
    As stated earlier, you get the list from the config, add your element to that list, then set that list again in the config.
     
  15. Offline

    To175

    AdamQpzm
    :(
    Maybe I can do that ?
    Code:java
    1. List<String> list = getConfig().getStringList("BannedPlayers");
    2. list.add(args[1]);
     
Thread Status:
Not open for further replies.

Share This Page