From 1c0dd516e2630149eee10e7ba875bae65c7e45d2 Mon Sep 17 00:00:00 2001 From: Esophose Date: Mon, 3 Jan 2022 07:36:29 -0700 Subject: [PATCH] Updated config comment handling to support 1.18.1 properly --- build.gradle | 2 +- .../config/CommentedConfigurationSection.java | 20 +++++++++++++++++++ .../config/CommentedFileConfiguration.java | 14 ++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 932bdbd..36c7708 100644 --- a/build.gradle +++ b/build.gradle @@ -35,7 +35,7 @@ dependencies { compileOnly 'org.jetbrains:annotations:16.0.2' compileOnly 'me.clip:placeholderapi:2.10.4' compileOnly 'org.xerial:sqlite-jdbc:3.23.1' - compileOnly 'org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT' + compileOnly 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT' } shadowJar { diff --git a/src/main/java/dev/esophose/playerparticles/config/CommentedConfigurationSection.java b/src/main/java/dev/esophose/playerparticles/config/CommentedConfigurationSection.java index 4be0cd1..99e65df 100644 --- a/src/main/java/dev/esophose/playerparticles/config/CommentedConfigurationSection.java +++ b/src/main/java/dev/esophose/playerparticles/config/CommentedConfigurationSection.java @@ -393,4 +393,24 @@ public class CommentedConfigurationSection implements ConfigurationSection { this.config.addDefault(s, o); } + @Override + public List getComments(String path) { + throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods."); + } + + @Override + public List getInlineComments(String path) { + throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods."); + } + + @Override + public void setComments(String path, List comments) { + throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods."); + } + + @Override + public void setInlineComments(String path, List comments) { + throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods."); + } + } diff --git a/src/main/java/dev/esophose/playerparticles/config/CommentedFileConfiguration.java b/src/main/java/dev/esophose/playerparticles/config/CommentedFileConfiguration.java index e4cdcae..064b02f 100644 --- a/src/main/java/dev/esophose/playerparticles/config/CommentedFileConfiguration.java +++ b/src/main/java/dev/esophose/playerparticles/config/CommentedFileConfiguration.java @@ -76,13 +76,25 @@ public class CommentedFileConfiguration extends CommentedConfigurationSection { // Edit the configuration to how we want it try { - Field field_yamlOptions = YamlConfiguration.class.getDeclaredField("yamlOptions"); + Field field_yamlOptions; + try { + field_yamlOptions = YamlConfiguration.class.getDeclaredField("yamlOptions"); + } catch (NoSuchFieldException e) { // This is used for 1.18.1+ + field_yamlOptions = YamlConfiguration.class.getDeclaredField("yamlDumperOptions"); + } + field_yamlOptions.setAccessible(true); DumperOptions yamlOptions = (DumperOptions) field_yamlOptions.get(yamlConfiguration); yamlOptions.setWidth(Integer.MAX_VALUE); if (Stream.of(DumperOptions.class.getDeclaredMethods()).anyMatch(x -> x.getName().equals("setIndicatorIndent"))) yamlOptions.setIndicatorIndent(2); + + if (Stream.of(DumperOptions.class.getDeclaredMethods()).anyMatch(x -> x.getName().equals("setProcessComments"))) + yamlOptions.setProcessComments(false); + + if (Stream.of(DumperOptions.class.getDeclaredMethods()).anyMatch(x -> x.getName().equals("setSplitLines"))) + yamlOptions.setSplitLines(false); } catch (ReflectiveOperationException e) { e.printStackTrace(); }