From f3596b3fb8432b31e92df7ec3e144bf273f95428 Mon Sep 17 00:00:00 2001 From: DevDrizzy Date: Sat, 14 Oct 2023 11:04:23 +0500 Subject: [PATCH] Fix default config options not working Signed-off-by: DevDrizzy --- .../xyz/refinedev/api/storage/YamlStorage.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/xyz/refinedev/api/storage/YamlStorage.java b/src/main/java/xyz/refinedev/api/storage/YamlStorage.java index d390f04..edecc9a 100644 --- a/src/main/java/xyz/refinedev/api/storage/YamlStorage.java +++ b/src/main/java/xyz/refinedev/api/storage/YamlStorage.java @@ -55,10 +55,6 @@ public YamlStorage(JavaPlugin plugin, String name, boolean saveResource) { this.name = name; this.config = new YamlFile(file); - // Default options of this Yaml Storage - // User can set their own by overriding this method - this.setupConfigOptions(this.config.options()); - if (!file.exists()) { try { if (saveResource) { @@ -116,7 +112,6 @@ public void readConfig() { // between different keys, making config look awful if (configValue.comment().length() > 0) { this.config.path(configValue.path()).comment(configValue.comment()).blankLine(); - //this.config.setComment(configValue.path(), "\n#" + configValue.comment(), YamlCommentFormat.DEFAULT); } } catch (IllegalArgumentException | IllegalAccessException ex) { @@ -125,6 +120,11 @@ public void readConfig() { } this.addSeparateComments(); + + // Default options of this Yaml Storage + // User can set their own by overriding this method + this.setupConfigOptions(this.config.options()); + this.saveConfig(); } @@ -189,6 +189,7 @@ public void setupConfigOptions(YamlConfigurationOptions options) { options.charset(Charsets.UTF_8); options.useComments(true); options.quoteStyleDefaults().setQuoteStyle(String.class, QuoteStyle.DOUBLE); + options.quoteStyleDefaults().setQuoteStyle(List.class, QuoteStyle.DOUBLE); options.header(String.join("\n", this.getHeader())); } @@ -256,6 +257,10 @@ public void addComment(String path, String comment) { this.config.setComment(path, comment); } + public void addCommentWithBlankLine(String path, String comment) { + this.config.path(path).comment(comment).blankLine(); + } + public Object get(String path) { return this.config.contains(path) ? this.config.get(path) : null; }