dejvokep / boosted-yaml

A simple-to-use standalone Java library delivering boosted experience while working with YAML documents.
https://dejvokep.gitbook.io/boostedyaml/
Apache License 2.0
80 stars 8 forks source link

UpdaterSettings isnt working #37

Open sheduxdev opened 3 weeks ago

sheduxdev commented 3 weeks ago

My Old Config

file-version: 1

genel-ayarlar:
  sunucu-adı: "Oyunlayıcı Network"
  sunucu-prefixi: "&bOyunlayıcı"
  sunucu-domaini: "www.oyunlayici.net"

My New Config:

file-version: 2

genel-ayarlar:
  sunucu-adı: "Oyunlayıcı Network"
  sunucu-prefixi: "&bOyunlayıcı"
  sunucu-domaini: "www.oyunlayici.net"

test: "test"

My Code

    @Override
    public void load() {
        if (!dataFolder.exists()) {
            dataFolder.mkdirs();
        }

        File configFile = new File(dataFolder, "config.yml");
        try {
            config = YamlDocument.create(configFile,
                    Lobbyleyici.class.getResourceAsStream("config.yml"),
                    GeneralSettings.builder().setKeyFormat(GeneralSettings.KeyFormat.OBJECT).build(),
                    LoaderSettings.builder().setAutoUpdate(true).build(),
                    DumperSettings.DEFAULT,
                    UpdaterSettings.builder().setVersioning(new BasicVersioning("file-version")).build());
        } catch (IOException e) {
            e.printStackTrace();
            Bukkit.getConsoleSender().sendMessage("§c│ Bir hata oluştu lütfen destek ekibine ulaşın.");
        }
    }

Its doesnt change the config to new one

dejvokep commented 2 weeks ago

Good day,

Please make sure you're passing the correct defaults; try outputting the value of file-version after updating (in your case after creating the document).

Attaching the results from my testing:

        String file = "file-version: 1\n" +
                "\n" +
                "genel-ayarlar:\n" +
                "  sunucu-adı: \"Oyunlayıcı Network\"\n" +
                "  sunucu-prefixi: \"&bOyunlayıcı\"\n" +
                "  sunucu-domaini: \"www.oyunlayici.net\"\n";
        String defaults = "file-version: 2\n" +
                "\n" +
                "genel-ayarlar:\n" +
                "  sunucu-adı: \"Oyunlayıcı Network\"\n" +
                "  sunucu-prefixi: \"&bOyunlayıcı\"\n" +
                "  sunucu-domaini: \"www.oyunlayici.net\"\n" +
                "\n" +
                "test: \"test\"\n";

        YamlDocument document = YamlDocument.create(
                new ByteArrayInputStream(file.getBytes(StandardCharsets.UTF_8)),
                new ByteArrayInputStream(defaults.getBytes(StandardCharsets.UTF_8)),
                GeneralSettings.builder().setKeyFormat(GeneralSettings.KeyFormat.OBJECT).build(),
                LoaderSettings.builder().setAutoUpdate(true).build(),
                DumperSettings.DEFAULT,
                UpdaterSettings.builder().setVersioning(new BasicVersioning("file-version")).build()
        );

Dumping the document results in the same contents and structure as your defaults (apart from the quotation).

Have a nice day. ~ dejvokep