Using config.getStringLIst()

Discussion in 'Plugin Development' started by MrCreeper, Aug 21, 2011.

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

    MrCreeper

    Hey :)
    How can I use getStringList()?
    Code:java
    1. config = getConfiguration();
    2. List<String> flags = new ArrayList<String>();
    3.  
    4. flags.add("use");
    5. flags.add("pvp");
    6. flags.add("leaf-decay");
    7. flags.add("tnt");
    8.  
    9. flags = config.getStringList("Flags", flags);
    10. config.save()

    This is my code. It doesn't create something in config.yml. What's wrong here?
     
  2. Offline

    bergerkiller

    also add a setproperty part. :)
    Code:
    config.setProperty("Flags", flags);
    Right before the save() call.

    Btw: fastest reply ever? :D
     
  3. Offline

    krinsdeath

    None of the *List() methods actually write the provided default values to the configuration.

    Instead, you need to use config.setProperty("node.path", someList); config.save(); to write your defaults.
     
  4. Offline

    MrCreeper

    I assume that using setProperty would overwrite the existing list. How can I check if the list does already exist in the config? =)
     
  5. Offline

    bergerkiller

    You can try using this:
    Code:
    List<String> flags = config.getStringList("flags", null);
    if (flags == null) {
        //not read
    } else {
        //read
    }
     
Thread Status:
Not open for further replies.

Share This Page