mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-25 09:01:38 +01:00
Update to ConfigMe 1.2.0
This commit is contained in:
parent
e92721e597
commit
ac5868787a
2
pom.xml
2
pom.xml
@ -643,7 +643,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.jalu</groupId>
|
<groupId>ch.jalu</groupId>
|
||||||
<artifactId>configme</artifactId>
|
<artifactId>configme</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.2.0</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
@ -2,6 +2,7 @@ package fr.xephi.authme.message.updater;
|
|||||||
|
|
||||||
import ch.jalu.configme.configurationdata.ConfigurationDataImpl;
|
import ch.jalu.configme.configurationdata.ConfigurationDataImpl;
|
||||||
import ch.jalu.configme.properties.Property;
|
import ch.jalu.configme.properties.Property;
|
||||||
|
import ch.jalu.configme.properties.convertresult.PropertyValue;
|
||||||
import ch.jalu.configme.resource.PropertyReader;
|
import ch.jalu.configme.resource.PropertyReader;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
|
|
||||||
@ -23,9 +24,18 @@ public class MessageKeyConfigurationData extends ConfigurationDataImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initializeValues(PropertyReader reader) {
|
public void initializeValues(PropertyReader reader) {
|
||||||
getAllMessageProperties().stream()
|
for (Property<String> property : getAllMessageProperties()) {
|
||||||
.filter(prop -> prop.isPresent(reader))
|
PropertyValue<String> value = property.determineValue(reader);
|
||||||
.forEach(prop -> setValue(prop, prop.determineValue(reader)));
|
if (value.isValidInResource()) {
|
||||||
|
setValue(property, value.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T getValue(Property<T> property) {
|
||||||
|
// Override to silently return null if property is unknown
|
||||||
|
return (T) getValues().get(property.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -59,6 +59,11 @@ final class MessageMigraterPropertyReader implements PropertyReader {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getChildKeys(String s) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getObject(String path) {
|
public Object getObject(String path) {
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
|
@ -4,6 +4,7 @@ import ch.jalu.configme.configurationdata.ConfigurationData;
|
|||||||
import ch.jalu.configme.configurationdata.PropertyListBuilder;
|
import ch.jalu.configme.configurationdata.PropertyListBuilder;
|
||||||
import ch.jalu.configme.properties.Property;
|
import ch.jalu.configme.properties.Property;
|
||||||
import ch.jalu.configme.properties.StringProperty;
|
import ch.jalu.configme.properties.StringProperty;
|
||||||
|
import ch.jalu.configme.properties.convertresult.ConvertErrorRecorder;
|
||||||
import ch.jalu.configme.resource.PropertyReader;
|
import ch.jalu.configme.resource.PropertyReader;
|
||||||
import ch.jalu.configme.resource.PropertyResource;
|
import ch.jalu.configme.resource.PropertyResource;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
@ -177,7 +178,7 @@ public class MessageUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getFromReader(PropertyReader reader) {
|
protected String getFromReader(PropertyReader reader, ConvertErrorRecorder errorRecorder) {
|
||||||
return reader.getString(getPath());
|
return reader.getString(getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.xephi.authme.settings;
|
package fr.xephi.authme.settings;
|
||||||
|
|
||||||
import ch.jalu.configme.properties.BaseProperty;
|
import ch.jalu.configme.properties.BaseProperty;
|
||||||
|
import ch.jalu.configme.properties.convertresult.ConvertErrorRecorder;
|
||||||
import ch.jalu.configme.resource.PropertyReader;
|
import ch.jalu.configme.resource.PropertyReader;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -26,7 +27,7 @@ public class EnumSetProperty<E extends Enum<E>> extends BaseProperty<Set<E>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<E> getFromReader(PropertyReader reader) {
|
protected Set<E> getFromReader(PropertyReader reader, ConvertErrorRecorder errorRecorder) {
|
||||||
Object entry = reader.getObject(getPath());
|
Object entry = reader.getObject(getPath());
|
||||||
if (entry instanceof Collection<?>) {
|
if (entry instanceof Collection<?>) {
|
||||||
return ((Collection<?>) entry).stream()
|
return ((Collection<?>) entry).stream()
|
||||||
|
@ -3,6 +3,7 @@ package fr.xephi.authme.settings;
|
|||||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||||
import ch.jalu.configme.migration.PlainMigrationService;
|
import ch.jalu.configme.migration.PlainMigrationService;
|
||||||
import ch.jalu.configme.properties.Property;
|
import ch.jalu.configme.properties.Property;
|
||||||
|
import ch.jalu.configme.properties.convertresult.PropertyValue;
|
||||||
import ch.jalu.configme.resource.PropertyReader;
|
import ch.jalu.configme.resource.PropertyReader;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.initialization.DataFolder;
|
import fr.xephi.authme.initialization.DataFolder;
|
||||||
@ -214,7 +215,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
ConfigurationData configData) {
|
ConfigurationData configData) {
|
||||||
final String oldPath = "Security.console.noConsoleSpam";
|
final String oldPath = "Security.console.noConsoleSpam";
|
||||||
final Property<LogLevel> newProperty = PluginSettings.LOG_LEVEL;
|
final Property<LogLevel> newProperty = PluginSettings.LOG_LEVEL;
|
||||||
if (!newProperty.isPresent(reader) && reader.contains(oldPath)) {
|
if (!newProperty.isValidInResource(reader) && reader.contains(oldPath)) {
|
||||||
logger.info("Moving '" + oldPath + "' to '" + newProperty.getPath() + "'");
|
logger.info("Moving '" + oldPath + "' to '" + newProperty.getPath() + "'");
|
||||||
boolean oldValue = Optional.ofNullable(reader.getBoolean(oldPath)).orElse(false);
|
boolean oldValue = Optional.ofNullable(reader.getBoolean(oldPath)).orElse(false);
|
||||||
LogLevel level = oldValue ? LogLevel.INFO : LogLevel.FINE;
|
LogLevel level = oldValue ? LogLevel.INFO : LogLevel.FINE;
|
||||||
@ -252,17 +253,18 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
*/
|
*/
|
||||||
private static boolean convertToRegistrationType(PropertyReader reader, ConfigurationData configData) {
|
private static boolean convertToRegistrationType(PropertyReader reader, ConfigurationData configData) {
|
||||||
String oldEmailRegisterPath = "settings.registration.enableEmailRegistrationSystem";
|
String oldEmailRegisterPath = "settings.registration.enableEmailRegistrationSystem";
|
||||||
if (RegistrationSettings.REGISTRATION_TYPE.isPresent(reader) || !reader.contains(oldEmailRegisterPath)) {
|
if (RegistrationSettings.REGISTRATION_TYPE.isValidInResource(reader)
|
||||||
|
|| !reader.contains(oldEmailRegisterPath)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean useEmail = newProperty(oldEmailRegisterPath, false).determineValue(reader);
|
boolean useEmail = newProperty(oldEmailRegisterPath, false).determineValue(reader).getValue();
|
||||||
RegistrationType registrationType = useEmail ? RegistrationType.EMAIL : RegistrationType.PASSWORD;
|
RegistrationType registrationType = useEmail ? RegistrationType.EMAIL : RegistrationType.PASSWORD;
|
||||||
|
|
||||||
String useConfirmationPath = useEmail
|
String useConfirmationPath = useEmail
|
||||||
? "settings.registration.doubleEmailCheck"
|
? "settings.registration.doubleEmailCheck"
|
||||||
: "settings.restrictions.enablePasswordConfirmation";
|
: "settings.restrictions.enablePasswordConfirmation";
|
||||||
boolean hasConfirmation = newProperty(useConfirmationPath, false).determineValue(reader);
|
boolean hasConfirmation = newProperty(useConfirmationPath, false).determineValue(reader).getValue();
|
||||||
RegisterSecondaryArgument secondaryArgument = hasConfirmation
|
RegisterSecondaryArgument secondaryArgument = hasConfirmation
|
||||||
? RegisterSecondaryArgument.CONFIRMATION
|
? RegisterSecondaryArgument.CONFIRMATION
|
||||||
: RegisterSecondaryArgument.NONE;
|
: RegisterSecondaryArgument.NONE;
|
||||||
@ -287,7 +289,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
// We have two old settings replaced by only one: move the first non-empty one
|
// We have two old settings replaced by only one: move the first non-empty one
|
||||||
Property<String> oldUnloggedInGroup = newProperty("settings.security.unLoggedinGroup", "");
|
Property<String> oldUnloggedInGroup = newProperty("settings.security.unLoggedinGroup", "");
|
||||||
Property<String> oldRegisteredGroup = newProperty("GroupOptions.RegisteredPlayerGroup", "");
|
Property<String> oldRegisteredGroup = newProperty("GroupOptions.RegisteredPlayerGroup", "");
|
||||||
if (!oldUnloggedInGroup.determineValue(reader).isEmpty()) {
|
if (!oldUnloggedInGroup.determineValue(reader).getValue().isEmpty()) {
|
||||||
performedChanges = moveProperty(oldUnloggedInGroup, PluginSettings.REGISTERED_GROUP, reader, configData);
|
performedChanges = moveProperty(oldUnloggedInGroup, PluginSettings.REGISTERED_GROUP, reader, configData);
|
||||||
} else {
|
} else {
|
||||||
performedChanges = moveProperty(oldRegisteredGroup, PluginSettings.REGISTERED_GROUP, reader, configData);
|
performedChanges = moveProperty(oldRegisteredGroup, PluginSettings.REGISTERED_GROUP, reader, configData);
|
||||||
@ -311,13 +313,13 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
*/
|
*/
|
||||||
private static boolean moveDeprecatedHashAlgorithmIntoLegacySection(PropertyReader reader,
|
private static boolean moveDeprecatedHashAlgorithmIntoLegacySection(PropertyReader reader,
|
||||||
ConfigurationData configData) {
|
ConfigurationData configData) {
|
||||||
HashAlgorithm currentHash = SecuritySettings.PASSWORD_HASH.determineValue(reader);
|
HashAlgorithm currentHash = SecuritySettings.PASSWORD_HASH.determineValue(reader).getValue();
|
||||||
// Skip CUSTOM (has no class) and PLAINTEXT (is force-migrated later on in the startup process)
|
// Skip CUSTOM (has no class) and PLAINTEXT (is force-migrated later on in the startup process)
|
||||||
if (currentHash != HashAlgorithm.CUSTOM && currentHash != HashAlgorithm.PLAINTEXT) {
|
if (currentHash != HashAlgorithm.CUSTOM && currentHash != HashAlgorithm.PLAINTEXT) {
|
||||||
Class<?> encryptionClass = currentHash.getClazz();
|
Class<?> encryptionClass = currentHash.getClazz();
|
||||||
if (encryptionClass.isAnnotationPresent(Deprecated.class)) {
|
if (encryptionClass.isAnnotationPresent(Deprecated.class)) {
|
||||||
configData.setValue(SecuritySettings.PASSWORD_HASH, HashAlgorithm.SHA256);
|
configData.setValue(SecuritySettings.PASSWORD_HASH, HashAlgorithm.SHA256);
|
||||||
Set<HashAlgorithm> legacyHashes = SecuritySettings.LEGACY_HASHES.determineValue(reader);
|
Set<HashAlgorithm> legacyHashes = SecuritySettings.LEGACY_HASHES.determineValue(reader).getValue();
|
||||||
legacyHashes.add(currentHash);
|
legacyHashes.add(currentHash);
|
||||||
configData.setValue(SecuritySettings.LEGACY_HASHES, legacyHashes);
|
configData.setValue(SecuritySettings.LEGACY_HASHES, legacyHashes);
|
||||||
logger.warning("The hash algorithm '" + currentHash
|
logger.warning("The hash algorithm '" + currentHash
|
||||||
@ -352,9 +354,11 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
Property<String> commandProperty = newProperty("settings.restrictions.otherAccountsCmd", "");
|
Property<String> commandProperty = newProperty("settings.restrictions.otherAccountsCmd", "");
|
||||||
Property<Integer> commandThresholdProperty = newProperty("settings.restrictions.otherAccountsCmdThreshold", 0);
|
Property<Integer> commandThresholdProperty = newProperty("settings.restrictions.otherAccountsCmdThreshold", 0);
|
||||||
|
|
||||||
if (commandProperty.isPresent(reader) && commandThresholdProperty.determineValue(reader) >= 2) {
|
PropertyValue<String> commandPropValue = commandProperty.determineValue(reader);
|
||||||
oldOtherAccountsCommand = commandProperty.determineValue(reader);
|
int commandThreshold = commandThresholdProperty.determineValue(reader).getValue();
|
||||||
oldOtherAccountsCommandThreshold = commandThresholdProperty.determineValue(reader);
|
if (commandPropValue.isValidInResource() && commandThreshold >= 2) {
|
||||||
|
oldOtherAccountsCommand = commandPropValue.getValue();
|
||||||
|
oldOtherAccountsCommandThreshold = commandThreshold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,12 +376,13 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
Property<T> newProperty,
|
Property<T> newProperty,
|
||||||
PropertyReader reader,
|
PropertyReader reader,
|
||||||
ConfigurationData configData) {
|
ConfigurationData configData) {
|
||||||
if (reader.contains(oldProperty.getPath())) {
|
PropertyValue<T> oldPropertyValue = oldProperty.determineValue(reader);
|
||||||
|
if (oldPropertyValue.isValidInResource()) {
|
||||||
if (reader.contains(newProperty.getPath())) {
|
if (reader.contains(newProperty.getPath())) {
|
||||||
logger.info("Detected deprecated property " + oldProperty.getPath());
|
logger.info("Detected deprecated property " + oldProperty.getPath());
|
||||||
} else {
|
} else {
|
||||||
logger.info("Renaming " + oldProperty.getPath() + " to " + newProperty.getPath());
|
logger.info("Renaming " + oldProperty.getPath() + " to " + newProperty.getPath());
|
||||||
configData.setValue(newProperty, oldProperty.determineValue(reader));
|
configData.setValue(newProperty, oldPropertyValue.getValue());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ class CommandMigrationService implements MigrationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkAndMigrate(PropertyReader reader, ConfigurationData configurationData) {
|
public boolean checkAndMigrate(PropertyReader reader, ConfigurationData configurationData) {
|
||||||
final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.determineValue(reader);
|
final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.determineValue(reader).getValue();
|
||||||
if (moveOtherAccountsConfig(commandConfig) || isAnyCommandMissing(reader)) {
|
if (moveOtherAccountsConfig(commandConfig) || isAnyCommandMissing(reader)) {
|
||||||
configurationData.setValue(CommandSettingsHolder.COMMANDS, commandConfig);
|
configurationData.setValue(CommandSettingsHolder.COMMANDS, commandConfig);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user