Merge branch 'master' of https://github.com/AuthMe/AuthMeReloaded into delay-commands-event
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.resource.PropertyResource;
|
||||
import ch.jalu.configme.properties.BaseProperty;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -15,7 +15,7 @@ import static com.google.common.collect.Sets.newHashSet;
|
||||
*
|
||||
* @param <E> the enum type
|
||||
*/
|
||||
public class EnumSetProperty<E extends Enum<E>> extends Property<Set<E>> {
|
||||
public class EnumSetProperty<E extends Enum<E>> extends BaseProperty<Set<E>> {
|
||||
|
||||
private final Class<E> enumClass;
|
||||
|
||||
@@ -26,8 +26,8 @@ public class EnumSetProperty<E extends Enum<E>> extends Property<Set<E>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<E> getFromResource(PropertyResource resource) {
|
||||
Object entry = resource.getObject(getPath());
|
||||
protected Set<E> getFromReader(PropertyReader reader) {
|
||||
Object entry = reader.getObject(getPath());
|
||||
if (entry instanceof Collection<?>) {
|
||||
return ((Collection<?>) entry).stream()
|
||||
.map(val -> toEnum(String.valueOf(val)))
|
||||
@@ -45,4 +45,11 @@ public class EnumSetProperty<E extends Enum<E>> extends Property<Set<E>> {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toExportValue(Set<E> value) {
|
||||
return value.stream()
|
||||
.map(Enum::name)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.configme.SettingsManagerImpl;
|
||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||
import ch.jalu.configme.migration.MigrationService;
|
||||
import ch.jalu.configme.resource.PropertyResource;
|
||||
@@ -16,7 +16,7 @@ import static fr.xephi.authme.util.FileUtils.copyFileFromResource;
|
||||
/**
|
||||
* The AuthMe settings manager.
|
||||
*/
|
||||
public class Settings extends SettingsManager {
|
||||
public class Settings extends SettingsManagerImpl {
|
||||
|
||||
private final File pluginFolder;
|
||||
private String passwordEmailMessage;
|
||||
@@ -33,7 +33,7 @@ public class Settings extends SettingsManager {
|
||||
*/
|
||||
public Settings(File pluginFolder, PropertyResource resource, MigrationService migrationService,
|
||||
ConfigurationData configurationData) {
|
||||
super(resource, migrationService, configurationData);
|
||||
super(resource, configurationData, migrationService);
|
||||
this.pluginFolder = pluginFolder;
|
||||
loadSettingsFromFiles();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||
import ch.jalu.configme.migration.PlainMigrationService;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.resource.PropertyResource;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
@@ -25,6 +26,7 @@ import java.util.Set;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newListProperty;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
import static fr.xephi.authme.settings.properties.DatabaseSettings.MYSQL_POOL_SIZE;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.DELAY_JOIN_MESSAGE;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.REMOVE_JOIN_MESSAGE;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.REMOVE_LEAVE_MESSAGE;
|
||||
@@ -53,33 +55,33 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("checkstyle:BooleanExpressionComplexity")
|
||||
protected boolean performMigrations(PropertyResource resource, List<Property<?>> properties) {
|
||||
protected boolean performMigrations(PropertyReader reader, ConfigurationData configurationData) {
|
||||
boolean changes = false;
|
||||
if ("[a-zA-Z0-9_?]*".equals(resource.getString(ALLOWED_NICKNAME_CHARACTERS.getPath()))) {
|
||||
resource.setValue(ALLOWED_NICKNAME_CHARACTERS.getPath(), "[a-zA-Z0-9_]*");
|
||||
if ("[a-zA-Z0-9_?]*".equals(reader.getString(ALLOWED_NICKNAME_CHARACTERS.getPath()))) {
|
||||
configurationData.setValue(ALLOWED_NICKNAME_CHARACTERS, "[a-zA-Z0-9_]*");
|
||||
changes = true;
|
||||
}
|
||||
|
||||
setOldOtherAccountsCommandFieldsIfSet(resource);
|
||||
setOldOtherAccountsCommandFieldsIfSet(reader);
|
||||
|
||||
// Note ljacqu 20160211: Concatenating migration methods with | instead of the usual ||
|
||||
// ensures that all migrations will be performed
|
||||
return changes
|
||||
| performMailTextToFileMigration(resource)
|
||||
| migrateJoinLeaveMessages(resource)
|
||||
| migrateForceSpawnSettings(resource)
|
||||
| migratePoolSizeSetting(resource)
|
||||
| changeBooleanSettingToLogLevelProperty(resource)
|
||||
| hasOldHelpHeaderProperty(resource)
|
||||
| hasSupportOldPasswordProperty(resource)
|
||||
| convertToRegistrationType(resource)
|
||||
| mergeAndMovePermissionGroupSettings(resource)
|
||||
| moveDeprecatedHashAlgorithmIntoLegacySection(resource)
|
||||
| moveSaltColumnConfigWithOtherColumnConfigs(resource)
|
||||
|| hasDeprecatedProperties(resource);
|
||||
| performMailTextToFileMigration(reader)
|
||||
| migrateJoinLeaveMessages(reader, configurationData)
|
||||
| migrateForceSpawnSettings(reader, configurationData)
|
||||
| migratePoolSizeSetting(reader, configurationData)
|
||||
| changeBooleanSettingToLogLevelProperty(reader, configurationData)
|
||||
| hasOldHelpHeaderProperty(reader)
|
||||
| hasSupportOldPasswordProperty(reader)
|
||||
| convertToRegistrationType(reader, configurationData)
|
||||
| mergeAndMovePermissionGroupSettings(reader, configurationData)
|
||||
| moveDeprecatedHashAlgorithmIntoLegacySection(reader, configurationData)
|
||||
| moveSaltColumnConfigWithOtherColumnConfigs(reader, configurationData)
|
||||
|| hasDeprecatedProperties(reader);
|
||||
}
|
||||
|
||||
private static boolean hasDeprecatedProperties(PropertyResource resource) {
|
||||
private static boolean hasDeprecatedProperties(PropertyReader reader) {
|
||||
String[] deprecatedProperties = {
|
||||
"Converter.Rakamak.newPasswordHash", "Hooks.chestshop", "Hooks.legacyChestshop", "Hooks.notifications",
|
||||
"Passpartu", "Performances", "settings.restrictions.enablePasswordVerifier", "Xenoforo.predefinedSalt",
|
||||
@@ -90,7 +92,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
"settings.sessions.sessionExpireOnIpChange", "settings.restrictions.otherAccountsCmd",
|
||||
"settings.restrictions.otherAccountsCmdThreshold"};
|
||||
for (String deprecatedPath : deprecatedProperties) {
|
||||
if (resource.contains(deprecatedPath)) {
|
||||
if (reader.contains(deprecatedPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -119,12 +121,12 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
/**
|
||||
* Check if {@code Email.mailText} is present and move it to the Email.html file if it doesn't exist yet.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @return True if a migration has been completed, false otherwise
|
||||
*/
|
||||
private boolean performMailTextToFileMigration(PropertyResource resource) {
|
||||
private boolean performMailTextToFileMigration(PropertyReader reader) {
|
||||
final String oldSettingPath = "Email.mailText";
|
||||
final String oldMailText = resource.getString(oldSettingPath);
|
||||
final String oldMailText = reader.getString(oldSettingPath);
|
||||
if (oldMailText == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -149,12 +151,13 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
* Detect deprecated {@code settings.delayJoinLeaveMessages} and inform user of new "remove join messages"
|
||||
* and "remove leave messages" settings.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean migrateJoinLeaveMessages(PropertyResource resource) {
|
||||
private static boolean migrateJoinLeaveMessages(PropertyReader reader, ConfigurationData configData) {
|
||||
Property<Boolean> oldDelayJoinProperty = newProperty("settings.delayJoinLeaveMessages", false);
|
||||
boolean hasMigrated = moveProperty(oldDelayJoinProperty, DELAY_JOIN_MESSAGE, resource);
|
||||
boolean hasMigrated = moveProperty(oldDelayJoinProperty, DELAY_JOIN_MESSAGE, reader, configData);
|
||||
|
||||
if (hasMigrated) {
|
||||
ConsoleLogger.info(String.format("Note that we now also have the settings %s and %s",
|
||||
@@ -167,31 +170,33 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
* Detects old "force spawn loc on join" and "force spawn on these worlds" settings and moves them
|
||||
* to the new paths.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean migrateForceSpawnSettings(PropertyResource resource) {
|
||||
private static boolean migrateForceSpawnSettings(PropertyReader reader, ConfigurationData configData) {
|
||||
Property<Boolean> oldForceLocEnabled = newProperty(
|
||||
"settings.restrictions.ForceSpawnLocOnJoinEnabled", false);
|
||||
Property<List<String>> oldForceWorlds = newListProperty(
|
||||
"settings.restrictions.ForceSpawnOnTheseWorlds", "world", "world_nether", "world_the_ed");
|
||||
|
||||
return moveProperty(oldForceLocEnabled, FORCE_SPAWN_LOCATION_AFTER_LOGIN, resource)
|
||||
| moveProperty(oldForceWorlds, FORCE_SPAWN_ON_WORLDS, resource);
|
||||
return moveProperty(oldForceLocEnabled, FORCE_SPAWN_LOCATION_AFTER_LOGIN, reader, configData)
|
||||
| moveProperty(oldForceWorlds, FORCE_SPAWN_ON_WORLDS, reader, configData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects the old auto poolSize value and replaces it with the default value.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean migratePoolSizeSetting(PropertyResource resource) {
|
||||
Integer oldValue = resource.getInt("DataSource.poolSize");
|
||||
if(oldValue == null || oldValue > 0) {
|
||||
private static boolean migratePoolSizeSetting(PropertyReader reader, ConfigurationData configData) {
|
||||
Integer oldValue = reader.getInt(MYSQL_POOL_SIZE.getPath());
|
||||
if (oldValue == null || oldValue > 0) {
|
||||
return false;
|
||||
}
|
||||
resource.setValue("DataSource.poolSize", 10);
|
||||
configData.setValue(MYSQL_POOL_SIZE, 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -199,24 +204,26 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
* Changes the old boolean property "hide spam from console" to the new property specifying
|
||||
* the log level.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean changeBooleanSettingToLogLevelProperty(PropertyResource resource) {
|
||||
private static boolean changeBooleanSettingToLogLevelProperty(PropertyReader reader,
|
||||
ConfigurationData configData) {
|
||||
final String oldPath = "Security.console.noConsoleSpam";
|
||||
final Property<LogLevel> newProperty = PluginSettings.LOG_LEVEL;
|
||||
if (!newProperty.isPresent(resource) && resource.contains(oldPath)) {
|
||||
if (!newProperty.isPresent(reader) && reader.contains(oldPath)) {
|
||||
ConsoleLogger.info("Moving '" + oldPath + "' to '" + newProperty.getPath() + "'");
|
||||
boolean oldValue = MoreObjects.firstNonNull(resource.getBoolean(oldPath), false);
|
||||
boolean oldValue = MoreObjects.firstNonNull(reader.getBoolean(oldPath), false);
|
||||
LogLevel level = oldValue ? LogLevel.INFO : LogLevel.FINE;
|
||||
resource.setValue(newProperty.getPath(), level.name());
|
||||
configData.setValue(newProperty, level);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean hasOldHelpHeaderProperty(PropertyResource resource) {
|
||||
if (resource.contains("settings.helpHeader")) {
|
||||
private static boolean hasOldHelpHeaderProperty(PropertyReader reader) {
|
||||
if (reader.contains("settings.helpHeader")) {
|
||||
ConsoleLogger.warning("Help header setting is now in messages/help_xx.yml, "
|
||||
+ "please check the file to set it again");
|
||||
return true;
|
||||
@@ -224,9 +231,9 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean hasSupportOldPasswordProperty(PropertyResource resource) {
|
||||
private static boolean hasSupportOldPasswordProperty(PropertyReader reader) {
|
||||
String path = "settings.security.supportOldPasswordHash";
|
||||
if (resource.contains(path)) {
|
||||
if (reader.contains(path)) {
|
||||
ConsoleLogger.warning("Property '" + path + "' is no longer supported. "
|
||||
+ "Use '" + SecuritySettings.LEGACY_HASHES.getPath() + "' instead.");
|
||||
return true;
|
||||
@@ -237,56 +244,58 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
/**
|
||||
* Converts old boolean configurations for registration to the new enum properties, if applicable.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean convertToRegistrationType(PropertyResource resource) {
|
||||
private static boolean convertToRegistrationType(PropertyReader reader, ConfigurationData configData) {
|
||||
String oldEmailRegisterPath = "settings.registration.enableEmailRegistrationSystem";
|
||||
if (RegistrationSettings.REGISTRATION_TYPE.isPresent(resource) || !resource.contains(oldEmailRegisterPath)) {
|
||||
if (RegistrationSettings.REGISTRATION_TYPE.isPresent(reader) || !reader.contains(oldEmailRegisterPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean useEmail = newProperty(oldEmailRegisterPath, false).getValue(resource);
|
||||
boolean useEmail = newProperty(oldEmailRegisterPath, false).determineValue(reader);
|
||||
RegistrationType registrationType = useEmail ? RegistrationType.EMAIL : RegistrationType.PASSWORD;
|
||||
|
||||
String useConfirmationPath = useEmail
|
||||
? "settings.registration.doubleEmailCheck"
|
||||
: "settings.restrictions.enablePasswordConfirmation";
|
||||
boolean hasConfirmation = newProperty(useConfirmationPath, false).getValue(resource);
|
||||
boolean hasConfirmation = newProperty(useConfirmationPath, false).determineValue(reader);
|
||||
RegisterSecondaryArgument secondaryArgument = hasConfirmation
|
||||
? RegisterSecondaryArgument.CONFIRMATION
|
||||
: RegisterSecondaryArgument.NONE;
|
||||
|
||||
ConsoleLogger.warning("Merging old registration settings into '"
|
||||
+ RegistrationSettings.REGISTRATION_TYPE.getPath() + "'");
|
||||
resource.setValue(RegistrationSettings.REGISTRATION_TYPE.getPath(), registrationType);
|
||||
resource.setValue(RegistrationSettings.REGISTER_SECOND_ARGUMENT.getPath(), secondaryArgument);
|
||||
configData.setValue(RegistrationSettings.REGISTRATION_TYPE, registrationType);
|
||||
configData.setValue(RegistrationSettings.REGISTER_SECOND_ARGUMENT, secondaryArgument);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates old permission group settings to the new configurations.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean mergeAndMovePermissionGroupSettings(PropertyResource resource) {
|
||||
private static boolean mergeAndMovePermissionGroupSettings(PropertyReader reader, ConfigurationData configData) {
|
||||
boolean performedChanges;
|
||||
|
||||
// We have two old settings replaced by only one: move the first non-empty one
|
||||
Property<String> oldUnloggedInGroup = newProperty("settings.security.unLoggedinGroup", "");
|
||||
Property<String> oldRegisteredGroup = newProperty("GroupOptions.RegisteredPlayerGroup", "");
|
||||
if (!oldUnloggedInGroup.getValue(resource).isEmpty()) {
|
||||
performedChanges = moveProperty(oldUnloggedInGroup, PluginSettings.REGISTERED_GROUP, resource);
|
||||
if (!oldUnloggedInGroup.determineValue(reader).isEmpty()) {
|
||||
performedChanges = moveProperty(oldUnloggedInGroup, PluginSettings.REGISTERED_GROUP, reader, configData);
|
||||
} else {
|
||||
performedChanges = moveProperty(oldRegisteredGroup, PluginSettings.REGISTERED_GROUP, resource);
|
||||
performedChanges = moveProperty(oldRegisteredGroup, PluginSettings.REGISTERED_GROUP, reader, configData);
|
||||
}
|
||||
|
||||
// Move paths of other old options
|
||||
performedChanges |= moveProperty(newProperty("GroupOptions.UnregisteredPlayerGroup", ""),
|
||||
PluginSettings.UNREGISTERED_GROUP, resource);
|
||||
PluginSettings.UNREGISTERED_GROUP, reader, configData);
|
||||
performedChanges |= moveProperty(newProperty("permission.EnablePermissionCheck", false),
|
||||
PluginSettings.ENABLE_PERMISSION_CHECK, resource);
|
||||
PluginSettings.ENABLE_PERMISSION_CHECK, reader, configData);
|
||||
return performedChanges;
|
||||
}
|
||||
|
||||
@@ -294,19 +303,21 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
* If a deprecated hash is used, it is added to the legacy hashes option and the active hash
|
||||
* is changed to SHA256.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean moveDeprecatedHashAlgorithmIntoLegacySection(PropertyResource resource) {
|
||||
HashAlgorithm currentHash = SecuritySettings.PASSWORD_HASH.getValue(resource);
|
||||
private static boolean moveDeprecatedHashAlgorithmIntoLegacySection(PropertyReader reader,
|
||||
ConfigurationData configData) {
|
||||
HashAlgorithm currentHash = SecuritySettings.PASSWORD_HASH.determineValue(reader);
|
||||
// Skip CUSTOM (has no class) and PLAINTEXT (is force-migrated later on in the startup process)
|
||||
if (currentHash != HashAlgorithm.CUSTOM && currentHash != HashAlgorithm.PLAINTEXT) {
|
||||
Class<?> encryptionClass = currentHash.getClazz();
|
||||
if (encryptionClass.isAnnotationPresent(Deprecated.class)) {
|
||||
resource.setValue(SecuritySettings.PASSWORD_HASH.getPath(), HashAlgorithm.SHA256);
|
||||
Set<HashAlgorithm> legacyHashes = SecuritySettings.LEGACY_HASHES.getValue(resource);
|
||||
configData.setValue(SecuritySettings.PASSWORD_HASH, HashAlgorithm.SHA256);
|
||||
Set<HashAlgorithm> legacyHashes = SecuritySettings.LEGACY_HASHES.determineValue(reader);
|
||||
legacyHashes.add(currentHash);
|
||||
resource.setValue(SecuritySettings.LEGACY_HASHES.getPath(), legacyHashes);
|
||||
configData.setValue(SecuritySettings.LEGACY_HASHES, legacyHashes);
|
||||
ConsoleLogger.warning("The hash algorithm '" + currentHash
|
||||
+ "' is no longer supported for active use. New hashes will be in SHA256.");
|
||||
return true;
|
||||
@@ -318,28 +329,30 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
/**
|
||||
* Moves the property for the password salt column name to the same path as all other column name properties.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean moveSaltColumnConfigWithOtherColumnConfigs(PropertyResource resource) {
|
||||
private static boolean moveSaltColumnConfigWithOtherColumnConfigs(PropertyReader reader,
|
||||
ConfigurationData configData) {
|
||||
Property<String> oldProperty = newProperty("ExternalBoardOptions.mySQLColumnSalt",
|
||||
DatabaseSettings.MYSQL_COL_SALT.getDefaultValue());
|
||||
return moveProperty(oldProperty, DatabaseSettings.MYSQL_COL_SALT, resource);
|
||||
return moveProperty(oldProperty, DatabaseSettings.MYSQL_COL_SALT, reader, configData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the old config to run a command when alt accounts are detected and sets them to this instance
|
||||
* for further processing.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
*/
|
||||
private void setOldOtherAccountsCommandFieldsIfSet(PropertyResource resource) {
|
||||
private void setOldOtherAccountsCommandFieldsIfSet(PropertyReader reader) {
|
||||
Property<String> commandProperty = newProperty("settings.restrictions.otherAccountsCmd", "");
|
||||
Property<Integer> commandThresholdProperty = newProperty("settings.restrictions.otherAccountsCmdThreshold", 0);
|
||||
|
||||
if (commandProperty.isPresent(resource) && commandThresholdProperty.getValue(resource) >= 2) {
|
||||
oldOtherAccountsCommand = commandProperty.getValue(resource);
|
||||
oldOtherAccountsCommandThreshold = commandThresholdProperty.getValue(resource);
|
||||
if (commandProperty.isPresent(reader) && commandThresholdProperty.determineValue(reader) >= 2) {
|
||||
oldOtherAccountsCommand = commandProperty.determineValue(reader);
|
||||
oldOtherAccountsCommandThreshold = commandThresholdProperty.determineValue(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,19 +361,21 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
*
|
||||
* @param oldProperty The old property (create a temporary {@link Property} object with the path)
|
||||
* @param newProperty The new property to move the value to
|
||||
* @param resource The property resource
|
||||
* @param reader The property reader
|
||||
* @param configData Configuration data
|
||||
* @param <T> The type of the property
|
||||
* @return True if a migration has been done, false otherwise
|
||||
*/
|
||||
private static <T> boolean moveProperty(Property<T> oldProperty,
|
||||
Property<T> newProperty,
|
||||
PropertyResource resource) {
|
||||
if (resource.contains(oldProperty.getPath())) {
|
||||
if (resource.contains(newProperty.getPath())) {
|
||||
protected static <T> boolean moveProperty(Property<T> oldProperty,
|
||||
Property<T> newProperty,
|
||||
PropertyReader reader,
|
||||
ConfigurationData configData) {
|
||||
if (reader.contains(oldProperty.getPath())) {
|
||||
if (reader.contains(newProperty.getPath())) {
|
||||
ConsoleLogger.info("Detected deprecated property " + oldProperty.getPath());
|
||||
} else {
|
||||
ConsoleLogger.info("Renaming " + oldProperty.getPath() + " to " + newProperty.getPath());
|
||||
resource.setValue(newProperty.getPath(), oldProperty.getValue(resource));
|
||||
configData.setValue(newProperty, oldProperty.determineValue(reader));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.configme.SettingsManagerBuilder;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
@@ -156,8 +157,11 @@ public class CommandManager implements Reloadable {
|
||||
File file = new File(dataFolder, "commands.yml");
|
||||
FileUtils.copyFileFromResource(file, "commands.yml");
|
||||
|
||||
SettingsManager settingsManager = new SettingsManager(
|
||||
YamlFileResourceProvider.loadFromFile(file), commandMigrationService, CommandSettingsHolder.class);
|
||||
SettingsManager settingsManager = SettingsManagerBuilder
|
||||
.withResource(YamlFileResourceProvider.loadFromFile(file))
|
||||
.configurationData(CommandSettingsHolder.class)
|
||||
.migrationService(commandMigrationService)
|
||||
.create();
|
||||
CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
|
||||
onJoinCommands = newReplacer(commandConfig.getOnJoin());
|
||||
onLoginCommands = newOnLoginCmdReplacer(commandConfig.getOnLogin());
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||
import ch.jalu.configme.migration.MigrationService;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.resource.PropertyResource;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import fr.xephi.authme.settings.SettingsMigrationService;
|
||||
@@ -30,10 +30,10 @@ class CommandMigrationService implements MigrationService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkAndMigrate(PropertyResource resource, List<Property<?>> properties) {
|
||||
final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.getValue(resource);
|
||||
if (moveOtherAccountsConfig(commandConfig) || isFileEmpty(resource)) {
|
||||
resource.setValue("", commandConfig);
|
||||
public boolean checkAndMigrate(PropertyReader reader, ConfigurationData configurationData) {
|
||||
final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.determineValue(reader);
|
||||
if (moveOtherAccountsConfig(commandConfig) || isAnyCommandMissing(reader)) {
|
||||
configurationData.setValue(CommandSettingsHolder.COMMANDS, commandConfig);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -59,7 +59,7 @@ class CommandMigrationService implements MigrationService {
|
||||
.replace("%playerip%", "%ip");
|
||||
}
|
||||
|
||||
private static boolean isFileEmpty(PropertyResource resource) {
|
||||
return COMMAND_CONFIG_PROPERTIES.stream().anyMatch(property -> resource.getObject(property) == null);
|
||||
private static boolean isAnyCommandMissing(PropertyReader reader) {
|
||||
return COMMAND_CONFIG_PROPERTIES.stream().anyMatch(property -> reader.getObject(property) == null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import ch.jalu.configme.SectionComments;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.configurationdata.CommentsConfiguration;
|
||||
import ch.jalu.configme.properties.BeanProperty;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Settings holder class for the commands.yml settings.
|
||||
*/
|
||||
@@ -16,12 +13,11 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
||||
public static final Property<CommandConfig> COMMANDS =
|
||||
new BeanProperty<>(CommandConfig.class, "", new CommandConfig());
|
||||
|
||||
|
||||
private CommandSettingsHolder() {
|
||||
}
|
||||
|
||||
@SectionComments
|
||||
public static Map<String, String[]> sectionComments() {
|
||||
@Override
|
||||
public void registerComments(CommentsConfiguration conf) {
|
||||
String[] rootComments = {
|
||||
"This configuration file allows you to execute commands on various events.",
|
||||
"Supported placeholders in commands:",
|
||||
@@ -67,21 +63,15 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
||||
" ifNumberOfAccountsAtLeast: 5"
|
||||
};
|
||||
|
||||
Map<String, String[]> commentMap = new HashMap<>();
|
||||
commentMap.put("", rootComments);
|
||||
commentMap.put("onFirstLogin", new String[]{
|
||||
"Commands to run for players logging in whose 'last login date' was empty"
|
||||
});
|
||||
commentMap.put("onUnregister", new String[]{
|
||||
"Commands to run whenever a player is unregistered (by himself, or by an admin)"
|
||||
});
|
||||
commentMap.put("onLogout", new String[]{
|
||||
conf.setComment("", rootComments);
|
||||
conf.setComment("onFirstLogin",
|
||||
"Commands to run for players logging in whose 'last login date' was empty");
|
||||
conf.setComment("onUnregister",
|
||||
"Commands to run whenever a player is unregistered (by himself, or by an admin)");
|
||||
conf.setComment("onLogout",
|
||||
"These commands are called whenever a logged in player uses /logout or quits.",
|
||||
"The commands are not run if a player that was not logged in quits the server.",
|
||||
"Note: if your server crashes, these commands won't be run, so don't rely on them to undo",
|
||||
"'onLogin' commands that would be dangerous for non-logged in players to have!"
|
||||
});
|
||||
return commentMap;
|
||||
"'onLogin' commands that would be dangerous for non-logged in players to have!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public final class AuthMeSettingsRetriever {
|
||||
* @return configuration data
|
||||
*/
|
||||
public static ConfigurationData buildConfigurationData() {
|
||||
return ConfigurationDataBuilder.collectData(
|
||||
return ConfigurationDataBuilder.createConfiguration(
|
||||
DatabaseSettings.class, PluginSettings.class, RestrictionSettings.class,
|
||||
EmailSettings.class, HooksSettings.class, ProtectionSettings.class,
|
||||
PurgeSettings.class, SecuritySettings.class, RegistrationSettings.class,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package fr.xephi.authme.settings.properties;
|
||||
|
||||
import ch.jalu.configme.Comment;
|
||||
import ch.jalu.configme.SectionComments;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.configurationdata.CommentsConfiguration;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
|
||||
@@ -51,9 +48,9 @@ public final class ConverterSettings implements SettingsHolder {
|
||||
private ConverterSettings() {
|
||||
}
|
||||
|
||||
@SectionComments
|
||||
public static Map<String, String[]> buildSectionComments() {
|
||||
return ImmutableMap.of("Converter",
|
||||
new String[]{"Converter settings: see https://github.com/AuthMe/AuthMeReloaded/wiki/Converters"});
|
||||
@Override
|
||||
public void registerComments(CommentsConfiguration conf) {
|
||||
conf.setComment("Converter",
|
||||
"Converter settings: see https://github.com/AuthMe/AuthMeReloaded/wiki/Converters");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
public final class DatabaseSettings implements SettingsHolder {
|
||||
|
||||
@Comment({"What type of database do you want to use?",
|
||||
"Valid values: SQLITE, MYSQL"})
|
||||
"Valid values: SQLITE, MYSQL, POSTGRESQL"})
|
||||
public static final Property<DataSourceType> BACKEND =
|
||||
newProperty(DataSourceType.class, "DataSource.backend", DataSourceType.SQLITE);
|
||||
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package fr.xephi.authme.settings.properties;
|
||||
|
||||
import ch.jalu.configme.Comment;
|
||||
import ch.jalu.configme.SectionComments;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.configurationdata.CommentsConfiguration;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import fr.xephi.authme.data.limbo.AllowFlightRestoreType;
|
||||
import fr.xephi.authme.data.limbo.WalkFlySpeedRestoreType;
|
||||
import fr.xephi.authme.data.limbo.persistence.LimboPersistenceType;
|
||||
import fr.xephi.authme.data.limbo.persistence.SegmentSize;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
|
||||
/**
|
||||
@@ -72,8 +69,8 @@ public final class LimboSettings implements SettingsHolder {
|
||||
private LimboSettings() {
|
||||
}
|
||||
|
||||
@SectionComments
|
||||
public static Map<String, String[]> createSectionComments() {
|
||||
@Override
|
||||
public void registerComments(CommentsConfiguration conf) {
|
||||
String[] limboExplanation = {
|
||||
"Before a user logs in, various properties are temporarily removed from the player,",
|
||||
"such as OP status, ability to fly, and walk/fly speed.",
|
||||
@@ -81,6 +78,6 @@ public final class LimboSettings implements SettingsHolder {
|
||||
"In this section, you may define how these properties should be handled.",
|
||||
"Read more at https://github.com/AuthMe/AuthMeReloaded/wiki/Limbo-players"
|
||||
};
|
||||
return ImmutableMap.of("limbo", limboExplanation);
|
||||
conf.setComment("limbo", limboExplanation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,10 @@ public final class ProtectionSettings implements SettingsHolder {
|
||||
@Comment({
|
||||
"Countries allowed to join the server and register. For country codes, see",
|
||||
"https://dev.maxmind.com/geoip/legacy/codes/iso3166/",
|
||||
"Use \"LOCALHOST\" for local addresses.",
|
||||
"PLEASE USE QUOTES!"})
|
||||
public static final Property<List<String>> COUNTRIES_WHITELIST =
|
||||
newListProperty("Protection.countries", "US", "GB");
|
||||
newListProperty("Protection.countries", "US", "GB", "LOCALHOST");
|
||||
|
||||
@Comment({
|
||||
"Countries not allowed to join the server and register",
|
||||
|
||||
@@ -5,9 +5,10 @@ import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newListProperty;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newLowercaseListProperty;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newLowercaseStringSetProperty;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
|
||||
public final class RestrictionSettings implements SettingsHolder {
|
||||
@@ -24,8 +25,8 @@ public final class RestrictionSettings implements SettingsHolder {
|
||||
newProperty("settings.restrictions.hideChat", false);
|
||||
|
||||
@Comment("Allowed commands for unauthenticated players")
|
||||
public static final Property<List<String>> ALLOW_COMMANDS =
|
||||
newLowercaseListProperty("settings.restrictions.allowCommands",
|
||||
public static final Property<Set<String>> ALLOW_COMMANDS =
|
||||
newLowercaseStringSetProperty("settings.restrictions.allowCommands",
|
||||
"/login", "/register", "/l", "/reg", "/email", "/captcha", "/2fa", "/totp");
|
||||
|
||||
@Comment({
|
||||
@@ -83,8 +84,8 @@ public final class RestrictionSettings implements SettingsHolder {
|
||||
" AllowedRestrictedUser:",
|
||||
" - playername;127.0.0.1",
|
||||
" - playername;regex:127\\.0\\.0\\..*"})
|
||||
public static final Property<List<String>> RESTRICTED_USERS =
|
||||
newLowercaseListProperty("settings.restrictions.AllowedRestrictedUser");
|
||||
public static final Property<Set<String>> RESTRICTED_USERS =
|
||||
newLowercaseStringSetProperty("settings.restrictions.AllowedRestrictedUser");
|
||||
|
||||
@Comment("Ban unknown IPs trying to log in with a restricted username?")
|
||||
public static final Property<Boolean> BAN_UNKNOWN_IP =
|
||||
@@ -177,8 +178,8 @@ public final class RestrictionSettings implements SettingsHolder {
|
||||
"- 'npcPlayer'",
|
||||
"- 'npcPlayer2'"
|
||||
})
|
||||
public static final Property<List<String>> UNRESTRICTED_NAMES =
|
||||
newLowercaseListProperty("settings.unrestrictions.UnrestrictedName");
|
||||
public static final Property<Set<String>> UNRESTRICTED_NAMES =
|
||||
newLowercaseStringSetProperty("settings.unrestrictions.UnrestrictedName");
|
||||
|
||||
private RestrictionSettings() {
|
||||
}
|
||||
|
||||
@@ -6,10 +6,9 @@ import ch.jalu.configme.properties.Property;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.EnumSetProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newLowercaseListProperty;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newLowercaseStringSetProperty;
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
|
||||
public final class SecuritySettings implements SettingsHolder {
|
||||
@@ -86,8 +85,8 @@ public final class SecuritySettings implements SettingsHolder {
|
||||
"- '123456'",
|
||||
"- 'password'",
|
||||
"- 'help'"})
|
||||
public static final Property<List<String>> UNSAFE_PASSWORDS =
|
||||
newLowercaseListProperty("settings.security.unsafePasswords",
|
||||
public static final Property<Set<String>> UNSAFE_PASSWORDS =
|
||||
newLowercaseStringSetProperty("settings.security.unsafePasswords",
|
||||
"123456", "password", "qwerty", "12345", "54321", "123456789", "help");
|
||||
|
||||
@Comment("Tempban a user's IP address if they enter the wrong password too many times")
|
||||
|
||||
Reference in New Issue
Block a user