mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-08 00:47:34 +01:00
Update to ConfigMe 1.4.0
This commit is contained in:
parent
80c1c2edac
commit
79309c3c05
2
pom.xml
2
pom.xml
@ -760,7 +760,7 @@
|
||||
<dependency>
|
||||
<groupId>ch.jalu</groupId>
|
||||
<artifactId>configme</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<version>1.4.0</version>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
@ -5,6 +5,7 @@ import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.properties.convertresult.PropertyValue;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.updater.MessageUpdater.MessageKeyProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -39,15 +40,19 @@ public class MessageKeyConfigurationData extends ConfigurationDataImpl {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Property<String>> getAllMessageProperties() {
|
||||
public List<MessageKeyProperty> getAllMessageProperties() {
|
||||
return (List) getProperties();
|
||||
}
|
||||
|
||||
public String getMessage(MessageKey messageKey) {
|
||||
return getValue(new MessageUpdater.MessageKeyProperty(messageKey));
|
||||
return getValue(new MessageKeyProperty(messageKey));
|
||||
}
|
||||
|
||||
public String getMessage(MessageKeyProperty property) {
|
||||
return (String) getValues().get(property.getPath());
|
||||
}
|
||||
|
||||
public void setMessage(MessageKey messageKey, String message) {
|
||||
setValue(new MessageUpdater.MessageKeyProperty(messageKey), message);
|
||||
setValue(new MessageKeyProperty(messageKey), message);
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ import ch.jalu.configme.exception.ConfigMeException;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -36,8 +36,8 @@ final class MessageMigraterPropertyReader implements PropertyReader {
|
||||
* @param file the file to load
|
||||
* @return the created property reader
|
||||
*/
|
||||
public static MessageMigraterPropertyReader loadFromFile(File file) {
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
public static MessageMigraterPropertyReader loadFromFile(Path file) {
|
||||
try (InputStream is = Files.newInputStream(file)) {
|
||||
return loadFromStream(is);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Error while reading file '" + file + "'", e);
|
||||
|
@ -2,7 +2,6 @@ package fr.xephi.authme.message.updater;
|
||||
|
||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||
import ch.jalu.configme.configurationdata.PropertyListBuilder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.properties.StringProperty;
|
||||
import ch.jalu.configme.properties.convertresult.ConvertErrorRecorder;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
@ -10,8 +9,8 @@ import ch.jalu.configme.resource.PropertyResource;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -102,9 +101,9 @@ public class MessageUpdater {
|
||||
|
||||
private boolean addMissingKeys(JarMessageSource jarMessageSource, MessageKeyConfigurationData configurationData) {
|
||||
List<String> addedKeys = new ArrayList<>();
|
||||
for (Property<String> property : configurationData.getAllMessageProperties()) {
|
||||
for (MessageKeyProperty property : configurationData.getAllMessageProperties()) {
|
||||
final String key = property.getPath();
|
||||
if (configurationData.getValue(property) == null) {
|
||||
if (configurationData.getMessage(property) == null) {
|
||||
configurationData.setValue(property, jarMessageSource.getMessageFromJar(property));
|
||||
addedKeys.add(key);
|
||||
}
|
||||
|
@ -2,8 +2,14 @@ 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;
|
||||
|
||||
@ -12,36 +18,43 @@ 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(getFile());
|
||||
return MessageMigraterPropertyReader.loadFromFile(getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Yaml createNewYaml() {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
// 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 String escapePathElementIfNeeded(String path) {
|
||||
return path;
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user