Updated config comment handling to support 1.18.1 properly

This commit is contained in:
Esophose 2022-01-03 07:36:29 -07:00
parent c60d90b261
commit 1c0dd516e2
No known key found for this signature in database
GPG key ID: DE0E013CAE5C630A
3 changed files with 34 additions and 2 deletions

View file

@ -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 {

View file

@ -393,4 +393,24 @@ public class CommentedConfigurationSection implements ConfigurationSection {
this.config.addDefault(s, o);
}
@Override
public List<String> getComments(String path) {
throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods.");
}
@Override
public List<String> getInlineComments(String path) {
throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods.");
}
@Override
public void setComments(String path, List<String> comments) {
throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods.");
}
@Override
public void setInlineComments(String path, List<String> comments) {
throw new IllegalStateException("CommentedConfigurationSection does not support Spigot-API comment methods.");
}
}

View file

@ -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();
}