diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 4f44363ae..fb75bbd34 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -17,10 +17,6 @@ import java.util.List; import java.util.logging.Logger; import java.util.zip.GZIPInputStream; -import me.muizers.Notifications.Notifications; -import net.citizensnpcs.Citizens; -import net.milkbowl.vault.permission.Permission; - import org.apache.logging.log4j.LogManager; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -74,6 +70,9 @@ import fr.xephi.authme.settings.OtherAccounts; import fr.xephi.authme.settings.PlayersLogs; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Spawn; +import me.muizers.Notifications.Notifications; +import net.citizensnpcs.Citizens; +import net.milkbowl.vault.permission.Permission; public class AuthMe extends JavaPlugin { @@ -200,37 +199,7 @@ public class AuthMe extends JavaPlugin { else ConsoleLogger.showError("Error while making Backup"); } - /* - * Backend MYSQL - FILE - SQLITE - */ - switch (Settings.getDataSource) { - case FILE: - FlatFile fileThread = new FlatFile(); - database = fileThread; - final int a = database.getAccountsRegistered(); - if (a >= 1000) { - ConsoleLogger.showError("YOU'RE USING FILE DATABASE WITH " + a + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!"); - } - break; - case MYSQL: - MySQL sqlThread = new MySQL(); - database = sqlThread; - break; - case SQLITE: - SQLite sqliteThread = new SQLite(); - database = sqliteThread; - final int b = database.getAccountsRegistered(); - if (b >= 2000) { - ConsoleLogger.showError("YOU'RE USING SQLITE DATABASE WITH " + b + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!"); - } - break; - } - - if (Settings.isCachingEnabled) { - database = new CacheDataSource(this, database); - } - - database = new DatabaseCalls(this, database); + setupDatabase(); dataManager = new DataManager(this, database); @@ -511,8 +480,8 @@ public class AuthMe extends JavaPlugin { return authme; } - public void savePlayer(Player player) throws IllegalStateException, - NullPointerException { + public void savePlayer(Player player) + throws IllegalStateException, NullPointerException { try { if ((citizens.isNPC(player, this)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { return; @@ -827,4 +796,33 @@ public class AuthMe extends JavaPlugin { } return realIP; } + + public void setupDatabase() { + /* + * Backend MYSQL - FILE - SQLITE + */ + switch (Settings.getDataSource) { + case FILE: + database = new FlatFile(); + final int a = database.getAccountsRegistered(); + if (a >= 1000) + ConsoleLogger.showError("YOU'RE USING FILE DATABASE WITH " + a + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!"); + break; + case MYSQL: + database = new MySQL(); + break; + case SQLITE: + database = new SQLite(); + final int b = database.getAccountsRegistered(); + if (b >= 2000) + ConsoleLogger.showError("YOU'RE USING SQLITE DATABASE WITH " + b + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!"); + break; + } + + if (Settings.isCachingEnabled) { + database = new CacheDataSource(this, database); + } + + database = new DatabaseCalls(this, database); + } } diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index 2d2467ebf..7532f8034 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -125,7 +125,6 @@ public class AdminCommand implements CommandExecutor { return true; } } else if (args[0].equalsIgnoreCase("reload")) { - database.reload(); File newConfigFile = new File("plugins" + File.separator + "AuthMe", "config.yml"); if (!newConfigFile.exists()) { InputStream fis = getClass().getResourceAsStream("" + File.separator + "config.yml"); @@ -156,6 +155,8 @@ public class AdminCommand implements CommandExecutor { Settings.reloadConfigOptions(newConfig); m.reLoad(); s.reLoad(); + plugin.database.close(); + plugin.setupDatabase(); m.send(sender, "reload"); } else if (args[0].equalsIgnoreCase("lastlogin")) { if (args.length != 2) {