Solved Config YAML problem [Need Help]

Discussion in 'Plugin Development' started by Josh014, Dec 28, 2014.

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

    Josh014

    Hello,

    I have a problem and I can't really figure it out. I want to add a player name to a list in my config.yml and it returns true instead of a player name.

    My code:
    Code:
    plugin.getConfig().getStringList("Eventdata.Players.List").add(player.getName());
    My returns:
    Code:
    Eventdata:
      Players:
        List: true
    Am I doing something wrong?

    Thanks in advance,
     
  2. @Josh014 Yes, you are doing something wrong xD
    What you're doing is creating a new list which has everyone from the Config list as well as player.getName();
    To update the list in the config, you would use plugin.getConfig().set();
     
  3. Offline

    Josh014

    @DJSkepter

    Alright but if I use "set(...)" it only stores one name.

    Code:
    Code:
    plugin.getConfig().set("Eventdata.Players.List", Arrays.asList(player.getName()));
     
  4. @Josh014 That's because you're only giving it a list with that name; You want to store it with the old list (by retrieving it using the method you used before) and then adding the player to that list, then using that list as the one to set it with.
     
  5. Offline

    Josh014

    @DJSkepter Alright, I think I get it now. Gonna try something.

    @DJSkepter Alright got it to work! Thanks for your help!

    For people with the same problem here is my code:
    Code:
    List<String> playerNames = plugin.getConfig().getStringList("Eventdata.Players.List");
                        playerNames.add(player.getName());
                       
                        plugin.getConfig().set("Eventdata.Players.List", playerNames);
    Greets

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
Thread Status:
Not open for further replies.

Share This Page