Revert "Update to ConfigMe 1.4.0"

- ConfigMe uses a different version from SnakeYAML, causing issues because it uses a newer configuration. For now, we stay on 1.3 as a quick fix.
This reverts commit 79309c3c05.
This commit is contained in:
ljacqu
2023-08-24 15:09:08 +02:00
parent 79309c3c05
commit 2de4a60f3a
5 changed files with 30 additions and 47 deletions
@@ -2,14 +2,8 @@ package fr.xephi.authme.message.updater;
import ch.jalu.configme.resource.PropertyReader;
import ch.jalu.configme.resource.YamlFileResource;
import ch.jalu.configme.resource.yaml.SnakeYamlNodeBuilder;
import ch.jalu.configme.resource.yaml.SnakeYamlNodeBuilderImpl;
import org.jetbrains.annotations.NotNull;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.ScalarNode;
import org.yaml.snakeyaml.nodes.Tag;
import java.io.File;
@@ -18,43 +12,36 @@ import java.io.File;
*/
public class MigraterYamlFileResource extends YamlFileResource {
private Yaml singleQuoteYaml;
public MigraterYamlFileResource(File file) {
super(file);
}
@Override
public PropertyReader createReader() {
return MessageMigraterPropertyReader.loadFromFile(getPath());
return MessageMigraterPropertyReader.loadFromFile(getFile());
}
@Override
protected Yaml createNewYaml() {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setAllowUnicode(true);
options.setProcessComments(true);
options.setIndent(4);
// Overridden setting: don't split lines
options.setSplitLines(false);
return new Yaml(options);
if (singleQuoteYaml == null) {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setAllowUnicode(true);
options.setDefaultScalarStyle(DumperOptions.ScalarStyle.SINGLE_QUOTED);
// Overridden setting: don't split lines
options.setSplitLines(false);
singleQuoteYaml = new Yaml(options);
}
return singleQuoteYaml;
}
// Because we set the YAML object to put strings in single quotes, this method by default uses that YAML object
// and also puts all paths as single quotes. Override to just always return the same string since we know those
// are only message names (so never any conflicting strings like "true" or "0").
@Override
protected @NotNull SnakeYamlNodeBuilder createNodeBuilder() {
return new MigraterYamlNodeBuilder();
}
/** Extended to represent all strings with single quotes in the YAML. */
private static final class MigraterYamlNodeBuilder extends SnakeYamlNodeBuilderImpl {
@Override
protected @NotNull Node createStringNode(@NotNull String value) {
return new ScalarNode(Tag.STR, value, null, null, DumperOptions.ScalarStyle.SINGLE_QUOTED);
}
@Override
public @NotNull Node createKeyNode(@NotNull String key) {
return super.createStringNode(key); // no single quotes
}
protected String escapePathElementIfNeeded(String path) {
return path;
}
}