Config file question

Discussion in 'Spigot Plugin Development' started by Ullrimax, Jun 2, 2017.

  1. Hi, for a plugin I would like to add things in my config files in order to some values for each world.
    I would like my config file looks like that :

    Worlds:
    world1:
    x:
    y:
    world2:
    x:
    y:
    world3:
    x:
    y:

    I hope you will understand, I want my config file looks like that but i don't know how to save "world1, x, y" in Worlds for example.
    Sorry I'm not english and it's a bit hard for me to explain my problem in english, If you have questions tell me
     
  2. Example:

    Code (Text):

    yamlConfig.set("Worlds.world1.name","TEXT");
    yamlConfig.set("Worlds.world1.x",100);
    yamlConfig.set("Worlds.world1.z",200);
     
     
  3. If you have a config like:
    Code (Text):
    Worlds:
       World1:
           x: 3
           y: 4
       World2:
           x: 1
           y: 2
    you can use a Map<String, Map<String, Integer>> to store the values.
    Then use YamlConfiguration#set(String, Object) to save the Map.

    To load it you will have to use YamlConfiguration#getConfigurationSection method.

    (This solution assumes you want unlimited number of World settings defined by the user)