From 7f11bc91cb1a3b3590fb5b6d0c9a4cfc81d6d315 Mon Sep 17 00:00:00 2001 From: mikigal Date: Fri, 9 Feb 2024 10:26:51 +0100 Subject: [PATCH] Fixed inline comments --- README.MD | 4 ++-- build.gradle | 2 +- .../mikigal/config/BukkitConfiguration.java | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) mode change 100644 => 100755 README.MD mode change 100644 => 100755 build.gradle mode change 100644 => 100755 src/main/java/pl/mikigal/config/BukkitConfiguration.java diff --git a/README.MD b/README.MD old mode 100644 new mode 100755 index b7e1bfd..837d25c --- a/README.MD +++ b/README.MD @@ -21,7 +21,7 @@ maven { url = 'https://repo.mikigal.pl/releases' } -compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.4' +compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.5' ``` #### Maven @@ -34,7 +34,7 @@ compile group: 'pl.mikigal', name: 'ConfigAPI', version: '1.2.4' pl.mikigal ConfigAPI - 1.2.4 + 1.2.5 compile ``` diff --git a/build.gradle b/build.gradle old mode 100644 new mode 100755 index befd0c3..378ea39 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'pl.mikigal' -version '1.2.4' +version '1.2.5' publishing { repositories { diff --git a/src/main/java/pl/mikigal/config/BukkitConfiguration.java b/src/main/java/pl/mikigal/config/BukkitConfiguration.java old mode 100644 new mode 100755 index 98acc26..09f4a83 --- a/src/main/java/pl/mikigal/config/BukkitConfiguration.java +++ b/src/main/java/pl/mikigal/config/BukkitConfiguration.java @@ -2,9 +2,7 @@ import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.configuration.file.YamlRepresenter; import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; import pl.mikigal.config.annotation.Comment; import pl.mikigal.config.exception.InvalidConfigException; import pl.mikigal.config.exception.MissingSerializerException; @@ -112,6 +110,8 @@ public Object get(String path) { */ @Override public String saveToString() { + this.overrideMaxLineWidth(); + String yaml = super.saveToString(); List lines = new ArrayList<>(); @@ -208,6 +208,21 @@ private void copyDefaultConfig() { } } + /** + * Set SnakeYaml's max line width to max Integer value. + * Required for inline comments + */ + private void overrideMaxLineWidth() { + try { + Field yamlOptionsField = YamlConfiguration.class.getDeclaredField("yamlOptions"); + yamlOptionsField.setAccessible(true); + DumperOptions yamlOptions = (DumperOptions) yamlOptionsField.get(this); + yamlOptions.setWidth(Integer.MAX_VALUE); + } catch (Exception e) { + throw new RuntimeException("Could not set max YAML line width", e); + } + } + /** * Add value to cache for optimization, to do not parse it every time user want to access it * @param path path in config