Solved Configuration string list

Discussion in 'Spigot Plugin Development' started by EvanTheSurfer, May 25, 2016.

  1. ok so my plugins config has multiple config sections. Each section needs to have its own string list that looks like this:
    Code (Text):
    AddedPlayers:
    - test
    - test1
    The probablem is I can not figure out how to do it. I have tried making a new array list in that method and setting the path value ".addedPlayers" to the addedPlayers list but it doesn't work. Please help. Thanks
     
  2. I don't understand please be more precise to what you want to do .
     
  3. I have a method that creates a config section when it is called. In that config section that is created when the event is called, I need it to create a string list. But this string list must be different for each config section that is created. Like this for example:
    Code (Text):
    Base1:
    Addedplayers:
    -
    -
    Base2:
    Addedplayers:
    -
    -
    When that method is called and when the config section is created, I need it to create a string list
     
  4. something like this ?

    Code (Java):
    Players:
    Player1:
       value: true
    Player2:
       value: true
    then make a string list

    Code (Java):
    AddedPlayers:
    - Player1
    - Player2
    is that so ?
     
  5. Yes
     
  6. so in my example

    Code (Java):
    Set<String> players = getConfig().getConfigurationSection("Players").getKeys(false);
    you can check every string at the config section players by doing a for loop statement

    Code (Java):
    for(String s : players) {
    list.add(s);
    }
    set your config AddedPlayers , list;
    then save your config;
     
  7. Ok so basically what I am saying is when I call the method, it creates a section in the config. The section name is the players name. When that method is called I need it to generate a default string list called addedPlayers. Like this:
    Code (Text):
    EvanOG:  //player name
    AddedPlayers;
      -
      -
     
  8. What have you tried?
     
  9. // config
    Code (Java):
    Config:
       s: true
    // getting the value of s
    Code (Java):
    getConfig().getBoole("Config.s");
    you can use the same way in setting the new value to config.
     
  10. I am not at my pc but I tried creating a new list in that method, and then did config.set(p.getName + "AddedPlayers", list); but whenever I tried to add or remove a string By getting the string list and removing a string, it doesn't work
     
  11. check what I've said

     
  12. Within Java, you use "." to separate sections/levels in YAML.

    Example:
    Code (Text):
    gangs:
      people:
        leader: Cewlt
        members:
        - person
      anothergang:
        leader: person
        members:
        - person
     
    Code (Text):
    String gangName = "people";
    getConfig().getString("gangs." + gangName + ".leader");
    getConfig().getStringList("gangs." + gangName + ".members");
    I hope I understood your question correctly, I still don't quite understanding what you're asking.
     
    • Like Like x 2
  13. I need to create a new string list in the config , not access one :)
     
  14. its the same way to as set.

    Code (Java):
    Config:
    after doing
    Code (Java):
    getConfig().set(Config.string, "test");
    saveConfig();
    Code (Java):
    Config:
       string: 'test'
     
  15. Along with what is said above:
    Code (Text):
    getConfig().set("gangs.people.leader", "gangleader");

    List<String> gangMembers = new ArrayList<String>();
    gangMembers.add("member1");

    getConfig().set("gangs.people.members", gangMembers);
     
  16. Figured it out. SOLVED