diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 28dce1e8f..047fe099e 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -241,8 +241,6 @@ public class AuthMe extends JavaPlugin { try { setupDatabase(newSettings); } catch (Exception e) { - ConsoleLogger.showError("If you are using CraftBukkit/Spigot 1.9 please add the " - + "-Dfile.encoding=UTF-8 argument in your server startup script!"); ConsoleLogger.logException("Fatal error occurred during database connection! " + "Authme initialization aborted!", e); stopOrUnload(); @@ -333,6 +331,91 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!"); } + /** Temporary method for reloading all stateful entities. */ + // TODO #432: Merge this with onEnable, not running things like Metrics multiple times where it would be bad + // Until then this method is a shameful copy of major parts of onEnable()... + public void reloadEntities() { + // Set various instances + server = getServer(); + plugin = this; + ConsoleLogger.setLogger(getLogger()); + + setPluginInfos(); + + // Load settings and custom configurations, if it fails, stop the server due to security reasons. + newSettings = createNewSetting(); + if (newSettings == null) { + ConsoleLogger.showError("Could not load configuration. Aborting."); + server.shutdown(); + return; + } + ConsoleLogger.setLoggingOptions(newSettings.getProperty(SecuritySettings.USE_LOGGING), + new File(getDataFolder(), "authme.log")); + + // Old settings manager + if (!loadSettings()) { + server.shutdown(); + setEnabled(false); + return; + } + + messages = new Messages(newSettings.getMessagesFile(), newSettings.getDefaultMessagesFile()); + + // Connect to the database and setup tables + try { + setupDatabase(newSettings); + } catch (Exception e) { + ConsoleLogger.logException("Fatal error occurred during database connection! " + + "Authme initialization aborted!", e); + stopOrUnload(); + return; + } + + passwordSecurity = new PasswordSecurity(getDataSource(), newSettings.getProperty(SecuritySettings.PASSWORD_HASH), + Bukkit.getPluginManager(), newSettings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH)); + + // Set up the permissions manager and command handler + permsMan = initializePermissionsManager(); + commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings); + + // Download and load GeoIp.dat file if absent + GeoLiteAPI.isDataAvailable(); + + // Set up the mail API + setupMailApi(); + + // Hooks + // Check Combat Tag Plus Version + checkCombatTagPlus(); + + // Check Multiverse + checkMultiverse(); + + // Check Essentials + checkEssentials(); + + // Check if the ProtocolLib is available. If so we could listen for + // inventory protection + checkProtocolLib(); + // End of Hooks + + dataManager = new DataManager(this); + + ProcessService processService = new ProcessService(newSettings, messages, this); + management = new Management(this, processService, database, PlayerCache.getInstance()); + + // Set up the BungeeCord hook + setupBungeeCordHook(); + + // Reload support hook + reloadSupportHook(); + + Spawn.reload(); + + // Show settings warnings + showSettingsWarnings(); + } + /** * Set up the mail API, if enabled. */ diff --git a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java index 177ccce56..81e305432 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java @@ -35,29 +35,6 @@ public class JsonCache { .create(); } - public void createCache(Player player, PlayerData playerData) { - if (player == null) { - return; - } - - String name = player.getName().toLowerCase(); - File file = new File(cacheDir, name + File.separator + "cache.json"); - if (file.exists()) { - return; - } - if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { - return; - } - - try { - String data = gson.toJson(playerData); - Files.touch(file); - Files.write(data, file, Charsets.UTF_8); - } catch (IOException e) { - ConsoleLogger.writeStackTrace(e); - } - } - public PlayerData readCache(Player player) { String name = player.getName().toLowerCase(); File file = new File(cacheDir, name + File.separator + "cache.json"); diff --git a/src/main/java/fr/xephi/authme/command/CommandService.java b/src/main/java/fr/xephi/authme/command/CommandService.java index a23acd10c..b7e6b91ec 100644 --- a/src/main/java/fr/xephi/authme/command/CommandService.java +++ b/src/main/java/fr/xephi/authme/command/CommandService.java @@ -13,7 +13,6 @@ import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.domain.Property; import org.bukkit.command.CommandSender; -import java.io.File; import java.util.List; /** @@ -167,15 +166,6 @@ public class CommandService { return messages.retrieve(key); } - /** - * Change the messages instance to retrieve messages from the given file. - * - * @param file The new file to read messages from - */ - public void reloadMessages(File file) { - messages.reload(file); - } - /** * Retrieve the given property's value. * diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java index 0c7adf2ff..7353abc73 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java @@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.settings.Spawn; import org.bukkit.command.CommandSender; import java.util.List; @@ -19,13 +18,7 @@ public class ReloadCommand implements ExecutableCommand { public void executeCommand(CommandSender sender, List arguments, CommandService commandService) { AuthMe plugin = commandService.getAuthMe(); try { - commandService.getSettings().reload(); - commandService.reloadMessages(commandService.getSettings().getMessagesFile()); - Spawn.reload(); - // TODO #432: We should not reload only certain plugin entities but actually reinitialize all elements, - // i.e. here in the future we might not have setupDatabase() but Authme.onEnable(), maybe after - // a call to some destructor method - plugin.setupDatabase(commandService.getSettings()); + plugin.reloadEntities(); commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); } catch (Exception e) { sender.sendMessage("Error occurred during reload of AuthMe: aborting"); diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index ad02c99f2..bb6049fa3 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -162,12 +162,6 @@ public class CacheDataSource implements DataSource { } } - @Override - public void reload() { // unused method - source.reload(); - cachedAuths.invalidateAll(); - } - @Override public synchronized boolean updateEmail(final PlayerAuth auth) { boolean result = source.updateEmail(auth); diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index 6e3bc09b4..29157480b 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -121,8 +121,6 @@ public interface DataSource { */ void close(); - void reload(); - /** * Method purgeBanned. * diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 72b301842..10f8a9a09 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -419,10 +419,6 @@ public class FlatFile implements DataSource { public synchronized void close() { } - @Override - public void reload() { - } - @Override public boolean updateEmail(PlayerAuth auth) { if (!isAuthAvailable(auth.getNickname())) { diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 84927fe64..7d21fa856 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -3,7 +3,6 @@ package fr.xephi.authme.datasource; import com.google.common.annotations.VisibleForTesting; import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.pool.HikariPool.PoolInitializationException; -import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.security.HashAlgorithm; @@ -695,17 +694,6 @@ public class MySQL implements DataSource { return false; } - @Override - public void reload() { - try { - reloadArguments(); - } catch (Exception ex) { - ConsoleLogger.logException("Can't reconnect to MySQL database... " + - "Please check your MySQL configuration! Encountered", ex); - AuthMe.getInstance().stopOrUnload(); - } - } - @Override public synchronized void close() { if (ds != null && !ds.isClosed()) { diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 2868a59a6..d526bc858 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -359,10 +359,6 @@ public class SQLite implements DataSource { } } - @Override - public void reload() { - } - private void close(Statement st) { if (st != null) { try { diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index 16ed81a96..d5cba2d79 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -26,7 +26,7 @@ public class GeoLiteAPI { } /** - * Download (if absent) the GeoIpLite data file and then try to load it. + * Download (if absent or old) the GeoIpLite data file and then try to load it. * * @return True if the data is available, false otherwise. */ diff --git a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java index d237c452b..63115518e 100644 --- a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java @@ -10,15 +10,14 @@ import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.settings.NewSetting; -import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.properties.SecuritySettings; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import java.io.File; import java.util.Arrays; import java.util.List; @@ -190,18 +189,6 @@ public class CommandServiceTest { verify(settings).getProperty(property); } - @Test - public void shouldReloadMessages() { - // given - File file = new File("some/bogus-file.test"); - - // when - commandService.reloadMessages(file); - - // then - verify(messages).reload(file); - } - @Test public void shouldReturnSettings() { // given/when