Carleslc / Simple-YAML

This Java API provides an easy-to-use way to store data and provide configurations using the YAML format.
https://carleslc.me/Simple-YAML
GNU General Public License v3.0
132 stars 38 forks source link

Formatting MapList indent #43

Closed HSGamer closed 2 years ago

HSGamer commented 3 years ago

My code:

        Config config = new PluginConfig(this, "config.yml");

        if (config.getConfig().isSet("test-path"))
            config.getConfig().getMapList("test-path").forEach(map -> map.forEach((o, o2) -> System.out.println(o + ": " + o2)));

        List<Map<String, Object>> mapList = new ArrayList<>();

        Map<String, Object> map1 = new HashMap<>();
        map1.put("1", "test1");
        map1.put("2", "test2");
        map1.put("3", "test3");
        mapList.add(map1);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("4", "test1");
        map2.put("5", "test2");
        map2.put("6", "test3");
        mapList.add(map2);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("7", "test1");
        map3.put("8", "test2");
        map3.put("9", "test3");
        mapList.add(map3);
        config.getConfig().set("test-path", mapList);

        config.saveConfig();
* Instead of
```yaml
test-path:
- '1': test1
  '2': test2
  '3': test3
- '4': test1
  '5': test2
  '6': test3
- '7': test1
  '8': test2
  '9': test3
Carleslc commented 3 years ago

This is the intended behaviour since version 1.7.1, where list indentation is the same as YamlConfiguration.options().indent() (2 by default).

Maybe an indentList option can be added to YamlConfigurationOptions to allow this customization.

Carleslc commented 2 years ago

The default behaviour was not working properly, so the fix and the indentList option has been released in 1.7.3. See #52 for further details.

Now your example is formatted by default as follows:

test-path:
  - '1': test1
    '2': test2
    '3': test3
  - '4': test1
    '5': test2
    '6': test3
  - '7': test1
    '8': test2
    '9': test3

You can remove the extra indent to match your example expected output setting indentList to 0.