How to: Config?

Discussion in 'Spigot Plugin Development' started by Fluddershy, Apr 14, 2017.

  1. This is my first question on the Spigot forum, and I just need a lot of help with configs. I have little to 0 knowledge about configs. Pretty much the only thing that I know how to do with them is strings. Like for say key: 124353. I can get that key. That's it. I need to learn how to create lists and get lists. I want to store locations and a lot of stuff with them. Can someone teach me how? Link me any helpful resources you've found helpful if you can. I look up videos and tutorials, but I just don't understand it. Thanks in advance!
     
  2. For the lists, do
    Code (Text):
    List<String> configlist = Arrays.asList("Test", "Etc.");
    //This works for storing strings, if you want something else
    //Change the string to that object
    getConfig().set("testlist", configlist);
    saveConfig();
    //To retrieve it either cast it like I'm going to or just use the
    //getStringList method
    List<String> retrieved = getConfig().getStringList("testlist");
    For the other stuff just create configuration sections and use the get method (not the getConfigurationSection one), but if you want a double or int remember to do getInt or getDouble.
    One more thing, the "." is the next segment of the configuration or in other words one line down and four spaces. You cannot make another config section after setting the value to something, unless it is in that segment or empty. One last thing, to delete configuration sections do
    Code (Text):
    getConfig().set("test", null);
    saveConfig();