How do I save a list for each player in the config?

Discussion in 'Plugin Development' started by Nukreeper64, Jan 9, 2015.

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

    Nukreeper64

    I am writing a plugin that must store a list of players in the config, and under each player name, there is a list of players that that player has added as a friend. What methods would I use to see if a player has added a certain other player, and what method would I use to add a single entry to the list? I tried creating a list, setting the list to getConfig().getList("playername") and then doing list.add(args[0]), and then setting the config section to the list, but it just threw a nullPointerException and erased most of my config. Is there a method to create or directly add to a list inside the config? Please just ask if you need to see more code or get more information.
    what I want config to look like:
    Code:
    Player1
    - Player2
    - Player3
    Player2
    - Player1
    - Player3
     
  2. Offline

    Skionz

    @Nukreeper64 Post your code. My guess is that 'list' is null. Alternatively args[0] may not exist resulting in an ArrayIndexOutOfBoundsException. Post all relevant classes in their entirety and any stack-traces.
     
  3. Offline

    Vextricity

    try setting the list to getStringList()
     
    1Rogue likes this.
  4. Offline

    1Rogue

    You can't modify the return value of getList(), as it returns a List<?>. You need to have it either cast to a type or use one of the built in functions such as @Vextricity suggested.
     
    Vextricity likes this.
Thread Status:
Not open for further replies.

Share This Page