Use injection in and for LimboCache, migrate some legacy settings, remove setGroup from Utils

- New injector method allows to retrieve services if they've already been instantiated -> useful for onDisable() which might be run after aborted initialization
- Deprecate various methods that need to be removed
This commit is contained in:
ljacqu
2016-06-12 16:14:06 +02:00
parent 347d7bcf46
commit d6e1fd5ceb
19 changed files with 226 additions and 198 deletions
@@ -14,22 +14,18 @@ import java.util.List;
/**
* Old settings manager. See {@link NewSetting} for the new manager.
*/
@Deprecated
public final class Settings {
public static List<String> getUnrestrictedName;
public static List<String> getForcedWorlds;
public static boolean isPermissionCheckEnabled;
public static boolean isForcedRegistrationEnabled;
public static boolean isTeleportToSpawnEnabled;
public static boolean isSessionsEnabled;
public static boolean isAllowRestrictedIp;
public static boolean isForceSpawnLocOnJoinEnabled;
public static boolean isSaveQuitLocationEnabled;
public static boolean protectInventoryBeforeLogInEnabled;
public static boolean isStopEnabled;
public static boolean reloadSupport;
public static boolean removePassword;
public static boolean multiverse;
public static boolean bungee;
public static boolean forceRegLogin;
public static boolean noTeleport;
@@ -41,9 +37,6 @@ public final class Settings {
public static String crazyloginFileName;
public static int getSessionTimeout;
public static int getNonActivatedGroup;
public static int maxLoginTry;
public static int captchaLength;
public static int getMaxLoginPerIp;
private static FileConfiguration configFile;
/**
@@ -58,13 +51,11 @@ public final class Settings {
private static void loadVariables() {
isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK);
isForcedRegistrationEnabled = load(RegistrationSettings.FORCE);
isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN);
isSessionsEnabled = load(PluginSettings.SESSIONS_ENABLED);
getSessionTimeout = configFile.getInt("settings.sessions.timeout", 10);
isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS);
isRemoveSpeedEnabled = load(RestrictionSettings.REMOVE_SPEED);
isForceSpawnLocOnJoinEnabled = load(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN);
isSaveQuitLocationEnabled = load(RestrictionSettings.SAVE_QUIT_LOCATION);
getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP);
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
@@ -74,15 +65,9 @@ public final class Settings {
protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN);
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
removePassword = configFile.getBoolean("Security.console.removePassword", true);
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
multiverse = load(HooksSettings.MULTIVERSE);
bungee = load(HooksSettings.BUNGEECORD);
getForcedWorlds = load(RestrictionSettings.FORCE_SPAWN_ON_WORLDS);
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
getMaxLoginPerIp = load(RestrictionSettings.MAX_LOGIN_PER_IP);
noTeleport = load(RestrictionSettings.NO_TELEPORT);
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
}
@@ -6,7 +6,8 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.FileUtils;
import fr.xephi.authme.util.StringUtils;
@@ -29,9 +30,10 @@ import java.io.IOException;
* should be taken from. In AuthMe, we can distinguish between the regular spawn and a "first spawn",
* to which players will be teleported who have joined for the first time.
*/
public class SpawnLoader implements SettingsDependent {
public class SpawnLoader implements Reloadable {
private final File authMeConfigurationFile;
private final NewSetting settings;
private final PluginHooks pluginHooks;
private final DataSource dataSource;
private FileConfiguration authMeConfiguration;
@@ -53,18 +55,17 @@ public class SpawnLoader implements SettingsDependent {
// TODO ljacqu 20160312: Check if resource could be copied and handle the case if not
FileUtils.copyFileFromResource(spawnFile, "spawn.yml");
this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml");
this.settings = settings;
this.pluginHooks = pluginHooks;
this.dataSource = dataSource;
loadSettings(settings);
reload();
}
/**
* Retrieve the relevant settings and load the AuthMe spawn.yml file.
*
* @param settings The settings instance
* (Re)loads the spawn file and relevant settings.
*/
@Override
public void loadSettings(NewSetting settings) {
public void reload() {
spawnPriority = settings.getProperty(RestrictionSettings.SPAWN_PRIORITY).split(",");
authMeConfiguration = YamlConfiguration.loadConfiguration(authMeConfigurationFile);
loadEssentialsSpawn();
@@ -159,7 +160,7 @@ public class SpawnLoader implements SettingsDependent {
}
break;
case "multiverse":
if (Settings.multiverse) {
if (settings.getProperty(HooksSettings.MULTIVERSE)) {
spawnLoc = pluginHooks.getMultiverseSpawn(world);
}
break;