diff --git a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java index 0982713c3..7b0241139 100644 --- a/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java +++ b/src/main/java/fr/xephi/authme/settings/SettingsMigrationService.java @@ -8,11 +8,14 @@ import org.bukkit.configuration.file.FileConfiguration; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.util.List; 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; import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS; +import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN; +import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_ON_WORLDS; /** * Service for verifying that the configuration is up-to-date. @@ -44,7 +47,8 @@ public class SettingsMigrationService { // ensures that all migrations will be performed return changes | performMailTextToFileMigration(configuration, pluginFolder) - | migrateJoinLeaveMessages(configuration); + | migrateJoinLeaveMessages(configuration) + | migrateForceSpawnSettings(configuration); } public boolean containsAllSettings(FileConfiguration configuration, PropertyMap propertyMap) { @@ -59,7 +63,8 @@ public class SettingsMigrationService { private static boolean hasDeprecatedProperties(FileConfiguration configuration) { String[] deprecatedProperties = { "Converter.Rakamak.newPasswordHash", "Hooks.chestshop", "Hooks.legacyChestshop", "Hooks.notifications", - "Passpartu", "Performances", "settings.restrictions.enablePasswordVerifier", "Xenoforo.predefinedSalt", "VeryGames"}; + "Passpartu", "Performances", "settings.restrictions.enablePasswordVerifier", "Xenoforo.predefinedSalt", + "VeryGames"}; for (String deprecatedPath : deprecatedProperties) { if (configuration.contains(deprecatedPath)) { return true; @@ -109,14 +114,50 @@ public class SettingsMigrationService { * @return True if the configuration has changed, false otherwise */ private static boolean migrateJoinLeaveMessages(FileConfiguration configuration) { - final String oldDelayJoinPath = "settings.delayJoinLeaveMessages"; - if (configuration.contains(oldDelayJoinPath)) { - ConsoleLogger.info("Detected deprecated property " + oldDelayJoinPath); + Property oldDelayJoinProperty = Property.newProperty("settings.delayJoinLeaveMessages", false); + boolean hasMigrated = moveProperty(oldDelayJoinProperty, DELAY_JOIN_MESSAGE, configuration); + + if (hasMigrated) { ConsoleLogger.info(String.format("Note that we now also have the settings %s and %s", REMOVE_JOIN_MESSAGE.getPath(), REMOVE_LEAVE_MESSAGE.getPath())); - if (!configuration.contains(DELAY_JOIN_MESSAGE.getPath())) { - configuration.set(DELAY_JOIN_MESSAGE.getPath(), true); - ConsoleLogger.info("Renamed " + oldDelayJoinPath + " to " + DELAY_JOIN_MESSAGE.getPath()); + } + return hasMigrated; + } + + /** + * Detect old "force spawn loc on join" and "force spawn on these worlds" settings and moves them + * to the new paths. + * + * @param configuration The file configuration + * @return True if the configuration has changed, false otherwise + */ + private static boolean migrateForceSpawnSettings(FileConfiguration configuration) { + Property oldForceLocEnabled = Property.newProperty( + "settings.restrictions.ForceSpawnLocOnJoinEnabled", false); + Property> oldForceWorlds = Property.newListProperty( + "settings.restrictions.ForceSpawnOnTheseWorlds", "world", "world_nether", "world_the_ed"); + + return moveProperty(oldForceLocEnabled, FORCE_SPAWN_LOCATION_AFTER_LOGIN, configuration) + | moveProperty(oldForceWorlds, FORCE_SPAWN_ON_WORLDS, configuration); + } + + /** + * Checks for an old property path and moves it to a new path if present. + * + * @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 configuration The file configuration + * @param The type of the property + * @return True if a migration has been done, false otherwise + */ + private static boolean moveProperty(Property oldProperty, + Property newProperty, + FileConfiguration configuration) { + if (configuration.contains(oldProperty.getPath())) { + ConsoleLogger.info("Detected deprecated property " + oldProperty.getPath()); + if (!configuration.contains(newProperty.getPath())) { + ConsoleLogger.info("Renamed " + oldProperty.getPath() + " to " + newProperty.getPath()); + configuration.set(newProperty.getPath(), oldProperty.getFromFile(configuration)); } return true; } diff --git a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java index 592e244c5..321737518 100644 --- a/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/properties/RestrictionSettings.java @@ -63,6 +63,13 @@ public class RestrictionSettings implements SettingsClass { public static final Property FORCE_SPAWN_LOCATION_AFTER_LOGIN = newProperty("settings.restrictions.ForceSpawnLocOnJoin.enabled", false); + @Comment({ + "WorldNames where we need to force the spawn location", + "Case-sensitive!"}) + public static final Property> FORCE_SPAWN_ON_WORLDS = + newListProperty("settings.restrictions.ForceSpawnLocOnJoin.worlds", + "world", "world_nether", "world_the_end"); + @Comment("This option will save the quit location of the players.") public static final Property SAVE_QUIT_LOCATION = newProperty("settings.restrictions.SaveQuitLocation", false); @@ -149,13 +156,6 @@ public class RestrictionSettings implements SettingsClass { public static final Property DISPLAY_OTHER_ACCOUNTS = newProperty("settings.restrictions.displayOtherAccounts", true); - @Comment({ - "WorldNames where we need to force the spawn location", - "Case-sensitive!"}) - public static final Property> FORCE_SPAWN_ON_WORLDS = - newListProperty("settings.restrictions.ForceSpawnLocOnJoin.worlds", - "world", "world_nether", "world_the_end"); - @Comment("Ban ip when the ip is not the ip registered in database") public static final Property BAN_UNKNOWN_IP = newProperty("settings.restrictions.banUnsafedIP", false);