Can't Add Element to List In YAML Config

Discussion in 'Plugin Development' started by GeekPlaya, Apr 22, 2012.

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

    GeekPlaya

    I am trying to add a string to a list within my configuration file. I am doing this from a separate class.

    Since it is unable to tell what type of elements are within the list, when I try to add an element to it, it returns an error. I've looked at the tutorials and they all say to do it this way, so I don't understand how I am the only one encountering a problem with this.

    Here is my code:
    Code:java
    1. final FileConfiguration config = plugin.getConfig();
    2. config.getList("players").add("Test");

    What looks wrong with that?

    Here is the error returned from Eclipse:
     
  2. Offline

    messageofdeath

    config.setList("players").add("Test");
    off my mind...
     
  3. Offline

    Sagacious_Zed Bukkit Docs

    Few things to note, getLIst() returns a list of type List<?> which you cannot add to, because you do not know what the list is of.
    getStringList() returns a new List and not the original one.

    Therefore, you have to do something like this.
    Code:
    config.set("players", config.getStringList("players").add("Test"));
     
    typicalGuy likes this.
  4. Offline

    Theodossis

    I am not sure but try it:
    Code:
    config.getList("players").set("Test");
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    The set method has more args than that, therefore that won't work.
     
Thread Status:
Not open for further replies.

Share This Page