From d3c1f06efb29d057a49327176c8c75fad3f62706 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 31 Jan 2016 21:52:03 +0100 Subject: [PATCH 01/18] Update Hungarian messages - Thanks to falconhome, via issue #470 --- src/main/resources/messages/messages_hu.yml | 60 ++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/resources/messages/messages_hu.yml b/src/main/resources/messages/messages_hu.yml index f52e4f2b9..bda53b143 100644 --- a/src/main/resources/messages/messages_hu.yml +++ b/src/main/resources/messages/messages_hu.yml @@ -6,16 +6,16 @@ login_msg: '&cKérlek jelentkezz be: "/login jelszó"' not_logged_in: '&cNem vagy bejelentkezve!' logout: '&cSikeresen kijelentkeztél' usage_log: '&cBejelentkezés: /login jelszó' -unknown_user: User is not in database +unknown_user: '&cA kért felhasználó nem telálható az adatbázisban' reg_voluntarily: Regisztrálhatod beceneved a szerveren a következö parancsal "/register jelszó jelszó" reg_disabled: '&cRegisztráció letiltva' no_perm: '&cNincs engedélyed' usage_reg: '&cHasználat: /register jelszó jelszóújra' -password_error_nick: '&fYou can''t use your name as password' -password_error_unsafe: '&fYou can''t use unsafe passwords' +password_error_nick: '&cNem használhatod a felhasználóneved jelszónak, kérlek válassz másikat...' +password_error_unsafe: '&cA választott jelszó nem biztonságos, kérlek válassz másikat...' unregistered: '&cRegisztráció sikeresen törölve!' same_nick: Ezen a játékosnéven már játszanak -valid_session: '&cSession login' +valid_session: '&2A hálózati kapcsolat újraépítése megtörtént.' pwd_changed: '&cJelszó cserélve!' reload: Beálítások és adatbázis újratöltve! timeout: Bejelentkezési idötúllépés @@ -29,31 +29,31 @@ reg_email_msg: '&cPlease register with "/register "' unsafe_spawn: A kilépési helyzeted nem biztonságos, teleportálás a kezdö Spawnra. max_reg: Csak egy karakterrel Registrálhatsz!!! password_error: A jelszó nem illik össze -invalid_session: Session Dataes doesnt corrispond Plaese wait the end of session +invalid_session: '&cAz IP címed megváltozott és a hálózati kapcsolatod lejárt. Kapcsolódj újra.' pass_len: A jelszavad nem éri el a minimális hosszat -vb_nonActiv: Your Account isent Activated yet check your Emails! +vb_nonActiv: '&cA felhasználód aktiválása még nem történt meg, ellenőrízd a leveleid!' usage_changepassword: 'használat: /changepassword régiJelszó újJelszó' -name_len: '&cYour nickname is too Short or too long' -regex: '&cYour nickname contains illegal characters. Allowed chars: REG_EX' -add_email: '&cPlease add your email with : /email add yourEmail confirmEmail' -recovery_email: '&cForgot your password? Please use /email recovery ' -usage_captcha: '&cUsage: /captcha ' -wrong_captcha: '&cWrong Captcha, please use : /captcha THE_CAPTCHA' -valid_captcha: '&cYour captcha is valid !' -kick_forvip: '&cA VIP Player join the full server!' -kick_fullserver: '&cThe server is actually full, Sorry!' -usage_email_add: '&fUsage: /email add ' -usage_email_change: '&fUsage: /email change ' -usage_email_recovery: '&fUsage: /email recovery ' -new_email_invalid: '[AuthMe] New email invalid!' -old_email_invalid: '[AuthMe] Old email invalid!' -email_invalid: '[AuthMe] Invalid Email' -email_added: '[AuthMe] Email Added !' -email_confirm: '[AuthMe] Confirm your Email !' -email_changed: '[AuthMe] Email Change !' -email_send: '[AuthMe] Recovery Email Send !' -country_banned: 'Your country is banned from this server' -antibot_auto_enabled: '[AuthMe] AntiBotMod automatically enabled due to massive connections!' -antibot_auto_disabled: '[AuthMe] AntiBotMod automatically disabled after %m Minutes, hope invasion stopped' -kick_antibot: 'AntiBot protection mode is enabled! You have to wait some minutes before joining the server.' -email_exists: '&cA recovery email was already sent! You can discard it and send a new one using the command below:' +name_len: '&4A felhasználó neved túl hosszú, vagy túl rövid! Próbálj másikat!' +regex: '&4A felhasználó neved nem használható karaktereket tartalmaz. Elfogadott karakterek: REG_EX' +add_email: '&3Kérlek add hozzá a felhasználódhoz az email címedet "/email add "' +recovery_email: '&3Ha elfelejtetted a jelszavad, használd az: "/email recovery "' +usage_captcha: '&3A bejelentkezéshez CAPTCHA szükséges, kérem használd a következő parancsot "/captcha "' +wrong_captcha: '&cHibás captcha, kérlek írd be a következő parancsot "/captcha THE_CAPTCHA" a chat-be!' +valid_captcha: '&2Captcha sikeresen feloldva!' +kick_forvip: '&3VIP játékos csatlakozott a szerverhez!' +kick_fullserver: '&4A szerver megtelt, próbáld később!' +usage_email_add: '&cHasználat: /email add ' +usage_email_change: '&cHasználat: /email change ' +usage_email_recovery: '&cHasználat: /email recovery ' +new_email_invalid: '&cHibás új email, próbáld újra!' +old_email_invalid: '&cHibás régi email, próbáld újra!' +email_invalid: '&cHibás emailcím, próbáld újra!' +email_added: '&2Az email címed rögzítése sikeresen megtörtént!' +email_confirm: '&cKérlek ellenőrízd az emailcímedet!' +email_changed: '&2Az email cím cseréje sikeresen megtörtént!' +email_send: '&2A jelszó visszaállításhoz szükséges emailt elküldtük! Ellenőrízd a leveleidet!' +email_exists: '&cA visszaállító emailt elküldtük! hiba esetén újrérheted az alábbi parancs segítségével:' +country_banned: '&4Az országod tiltólistán van ezen a szerveren!' +antibot_auto_enabled: '&4[AntiBotService] Az AntiBot védelem bekapcsolt a nagy számú hálózati kapcsolat miatt!' +antibot_auto_disabled: '&2[AntiBotService] Az AntiBot kikapcsol %m múlva!' +kick_antibot: 'Az AntiBot védelem bekapcsolva! Kérünk várj pár másodpercet a csatlakozáshoz.' From 11a03e5c4642b6414cb8c8bec9897fc8ae649769 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Mon, 1 Feb 2016 13:24:45 +0100 Subject: [PATCH 02/18] Update dependencies --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 33743bb12..7a77f60ff 100644 --- a/pom.xml +++ b/pom.xml @@ -129,7 +129,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.3 + 3.5 1.7 ${javaVersion} @@ -140,7 +140,7 @@ org.apache.maven.plugins maven-shade-plugin - 2.4.2 + 2.4.3 false false @@ -298,7 +298,7 @@ org.slf4j slf4j-jdk14 - 1.7.13 + 1.7.14 compile true @@ -335,7 +335,7 @@ com.maxmind.geoip geoip-api - 1.2.15 + 1.3.0 compile true From 15ca8284f48e10e4dadc321ed3033b1a0ddf5ef3 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Mon, 1 Feb 2016 23:26:33 +0100 Subject: [PATCH 03/18] Update messages_hu.yml Thanks to foxi69 --- src/main/resources/messages/messages_hu.yml | 72 ++++++++++----------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/src/main/resources/messages/messages_hu.yml b/src/main/resources/messages/messages_hu.yml index bda53b143..099179f80 100644 --- a/src/main/resources/messages/messages_hu.yml +++ b/src/main/resources/messages/messages_hu.yml @@ -4,56 +4,56 @@ registered: '&aSikeres regisztráció. Üdvözöllek!' user_regged: '&cJátékosnév már regisztrálva' login_msg: '&cKérlek jelentkezz be: "/login jelszó"' not_logged_in: '&cNem vagy bejelentkezve!' -logout: '&cSikeresen kijelentkeztél' -usage_log: '&cBejelentkezés: /login jelszó' -unknown_user: '&cA kért felhasználó nem telálható az adatbázisban' -reg_voluntarily: Regisztrálhatod beceneved a szerveren a következö parancsal "/register jelszó jelszó" -reg_disabled: '&cRegisztráció letiltva' -no_perm: '&cNincs engedélyed' -usage_reg: '&cHasználat: /register jelszó jelszóújra' +logout: '&cSikeresen kijelentkeztél!' +usage_log: '&cBejelentkezés: /login ' +unknown_user: '&cA kért felhasználó nem telálható az adatbázisban!' +reg_voluntarily: Regisztrálhatod magad a szerveren a következö parancsal "/register " +reg_disabled: '&cRegisztráció letiltva!' +no_perm: '&cNincs jogod ehhez!' +usage_reg: '&cHasználat: /register ' password_error_nick: '&cNem használhatod a felhasználóneved jelszónak, kérlek válassz másikat...' password_error_unsafe: '&cA választott jelszó nem biztonságos, kérlek válassz másikat...' unregistered: '&cRegisztráció sikeresen törölve!' -same_nick: Ezen a játékosnéven már játszanak +same_nick: 'Ezzel a játékosnévvel már játszanak a szerveren.' valid_session: '&2A hálózati kapcsolat újraépítése megtörtént.' pwd_changed: '&cJelszó cserélve!' -reload: Beálítások és adatbázis újratöltve! -timeout: Bejelentkezési idötúllépés -error: Hiba lépett fel; Lépj kapcsolatba a tulajjal' +reload: 'Beálítások és adatbázis újratöltve!' +timeout: 'Bejelentkezési időtúllépés!' +error: 'Hiba lépett fel; Lépj kapcsolatba a tulajjal' logged_in: '&cMár be vagy jelentkezve!' -login: '&aSikeresen Beléptél! Üdvözöllek!!!' -wrong_pwd: '&4Hibás jelszó' -user_unknown: '&cJátékosnév nem regisztrált' +login: '&aSikeresen beléptél!' +wrong_pwd: '&4Hibás jelszó!' +user_unknown: '&cEz a felhasználó nincs regisztrálva!' reg_msg: '&cKérlek Regisztrálj: "/register jelszó jelszóújra"' -reg_email_msg: '&cPlease register with "/register "' -unsafe_spawn: A kilépési helyzeted nem biztonságos, teleportálás a kezdö Spawnra. -max_reg: Csak egy karakterrel Registrálhatsz!!! -password_error: A jelszó nem illik össze +reg_email_msg: '&cKérlek regisztrálj: "/register "' +unsafe_spawn: 'A kilépési helyzeted nem biztonságos, teleportálás a Spawnra.' +max_reg: 'Csak egy karakterrel registrálhatsz!' +password_error: 'A két jelszó nem egyezik!' invalid_session: '&cAz IP címed megváltozott és a hálózati kapcsolatod lejárt. Kapcsolódj újra.' -pass_len: A jelszavad nem éri el a minimális hosszat -vb_nonActiv: '&cA felhasználód aktiválása még nem történt meg, ellenőrízd a leveleid!' -usage_changepassword: 'használat: /changepassword régiJelszó újJelszó' -name_len: '&4A felhasználó neved túl hosszú, vagy túl rövid! Próbálj másikat!' -regex: '&4A felhasználó neved nem használható karaktereket tartalmaz. Elfogadott karakterek: REG_EX' -add_email: '&3Kérlek add hozzá a felhasználódhoz az email címedet "/email add "' -recovery_email: '&3Ha elfelejtetted a jelszavad, használd az: "/email recovery "' -usage_captcha: '&3A bejelentkezéshez CAPTCHA szükséges, kérem használd a következő parancsot "/captcha "' +pass_len: 'A jelszavad nem éri el a minimális hosszúságot!' +vb_nonActiv: '&cA felhasználód aktiválása még nem történt meg, ellenőrizd a leveleid!' +usage_changepassword: 'Használat: /changepassword <új Jelszó>' +name_len: '&4A felhasználó neved túl hosszú, vagy túl rövid! Válassz másikat!' +regex: '&4A felhasználóneved nem használható karaktereket tartalmaz. Elfogadott karakterek: REG_EX' +add_email: '&3Kérlek add hozzá a felhasználódhoz az email címedet "/email add "' +recovery_email: '&3Ha elfelejtetted a jelszavad, használd az: "/email recovery "' +usage_captcha: '&3A bejelentkezéshez CAPTCHA szükséges, kérem használd a következő parancsot "/captcha "' wrong_captcha: '&cHibás captcha, kérlek írd be a következő parancsot "/captcha THE_CAPTCHA" a chat-be!' valid_captcha: '&2Captcha sikeresen feloldva!' kick_forvip: '&3VIP játékos csatlakozott a szerverhez!' -kick_fullserver: '&4A szerver megtelt, próbáld később!' -usage_email_add: '&cHasználat: /email add ' -usage_email_change: '&cHasználat: /email change ' +kick_fullserver: '&4A szerver megtelt, próbálj csatlakozni később!' +usage_email_add: '&cHasználat: /email add ' +usage_email_change: '&cHasználat: /email change <új Email>' usage_email_recovery: '&cHasználat: /email recovery ' -new_email_invalid: '&cHibás új email, próbáld újra!' -old_email_invalid: '&cHibás régi email, próbáld újra!' -email_invalid: '&cHibás emailcím, próbáld újra!' +new_email_invalid: '&cHibás az új email cím, próbáld újra!' +old_email_invalid: '&cHibás a régi email cím, próbáld újra!' +email_invalid: '&cHibás az email cím, próbáld újra!' email_added: '&2Az email címed rögzítése sikeresen megtörtént!' -email_confirm: '&cKérlek ellenőrízd az emailcímedet!' +email_confirm: '&cKérlek ellenőrízd az email címedet!' email_changed: '&2Az email cím cseréje sikeresen megtörtént!' email_send: '&2A jelszó visszaállításhoz szükséges emailt elküldtük! Ellenőrízd a leveleidet!' -email_exists: '&cA visszaállító emailt elküldtük! hiba esetén újrérheted az alábbi parancs segítségével:' +email_exists: '&cA visszaállító emailt elküldtük! Hiba esetén újkérheted az alábbi parancs segítségével:' country_banned: '&4Az országod tiltólistán van ezen a szerveren!' -antibot_auto_enabled: '&4[AntiBotService] Az AntiBot védelem bekapcsolt a nagy számú hálózati kapcsolat miatt!' -antibot_auto_disabled: '&2[AntiBotService] Az AntiBot kikapcsol %m múlva!' +antibot_auto_enabled: '&4[AntiBot] Az AntiBot védelem bekapcsolt a nagy számú hálózati kapcsolat miatt!' +antibot_auto_disabled: '&2[AntiBot] Az AntiBot kikapcsol %m múlva!' kick_antibot: 'Az AntiBot védelem bekapcsolva! Kérünk várj pár másodpercet a csatlakozáshoz.' From 4c265f18797284ce017a327675dcf0396265ce70 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Thu, 4 Feb 2016 15:03:52 +0100 Subject: [PATCH 04/18] Add an option to allow unlogged users to run all the commands Fix #456 --- .../fr/xephi/authme/listener/AuthMePlayerListener.java | 3 +++ src/main/java/fr/xephi/authme/settings/Settings.java | 7 ++++++- src/main/resources/config.yml | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 2e365e932..bae29ab74 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -108,6 +108,9 @@ public class AuthMePlayerListener implements Listener { if (Settings.useEssentialsMotd && cmd.equals("/motd")) { return; } + if(!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) { + return; + } if (Settings.allowCommands.contains(cmd)) { return; } diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 005a922b9..3fa437545 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -77,7 +77,7 @@ public final class Settings { enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect, - kickPlayersBeforeStopping, + kickPlayersBeforeStopping, allowAllCommandsIfRegIsOptional, customAttributes, generateImage, isRemoveSpeedEnabled, preventOtherCase; public static String helpHeader, getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, @@ -211,6 +211,7 @@ public final class Settings { isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true); reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true); + allowAllCommandsIfRegIsOptional = configFile.getBoolean("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false); allowCommands = new ArrayList<>(); allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha")); for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) { @@ -576,6 +577,10 @@ public final class Settings { set("settings.restrictions.enablePasswordVerifier", null); changes = true; } + if(!contains("settings.restrictions.allowAllCommandsIfRegistrationIsOptional")) { + set("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false); + changes = true; + } if (!contains("settings.security.unsafePasswords")) { List str = new ArrayList<>(); str.add("123456"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d2e0a9e74..67fa18a4e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -67,6 +67,9 @@ settings: # Care that this feature blocks also all the commands not # listed in the list below. allowChat: false + # WARNING: use this only if you need it! + # Allow unlogged users to use all the commands if registration is not forced! + allowAllCommandsIfRegistrationIsOptional: false # Commands allowed when a player is not authenticated allowCommands: - /login From e8a9b5c2e2d7fa88d5940bfc32cc52241f20a40d Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Thu, 4 Feb 2016 23:00:41 +0100 Subject: [PATCH 05/18] Add missing setting to the new Settings manager. --- .../xephi/authme/settings/custom/RestrictionSettings.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java b/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java index 32b68586d..ae5fe63db 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/RestrictionSettings.java @@ -18,13 +18,19 @@ public class RestrictionSettings implements SettingsClass { public static final Property ALLOW_CHAT = newProperty("settings.restrictions.allowChat", false); + @Comment({ + "Allow unlogged users to use all the commands if registration is not forced!", + "WARNING: use this only if you need it!)"}) + public static final Property ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL = + newProperty("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false); + @Comment("Allowed commands for unauthenticated players") public static final Property> ALLOW_COMMANDS = newProperty(PropertyType.STRING_LIST, "settings.restrictions.allowCommands", "login", "register", "l", "reg", "email", "captcha"); @Comment("Max number of allowed registrations per IP") - // TODO ljacqu 20160109: If 0 == unlimited, add this fact ot the comment + // TODO ljacqu 20160109: If 0 == unlimited, add this fact to the comment public static final Property MAX_REGISTRATION_PER_IP = newProperty("settings.restrictions.maxRegPerIp", 1); From 4f76398ce860b4fc68fa2b6dac9b31d999bb7c7c Mon Sep 17 00:00:00 2001 From: Xephi Date: Fri, 5 Feb 2016 13:24:38 +0100 Subject: [PATCH 06/18] #495 - Done --- src/main/java/fr/xephi/authme/AuthMe.java | 12 ++-- .../java/fr/xephi/authme/ConsoleLogger.java | 3 +- .../executable/authme/ReloadCommand.java | 3 +- .../authme/converter/RoyalAuthConverter.java | 3 +- .../authme/converter/vAuthFileReader.java | 2 +- .../authme/datasource/CacheDataSource.java | 2 +- .../fr/xephi/authme/datasource/MySQL.java | 72 +++++++------------ .../fr/xephi/authme/datasource/SQLite.java | 3 +- .../xephi/authme/modules/ModuleManager.java | 3 +- .../logout/ProcessSyncronousPlayerLogout.java | 8 +++ .../process/register/AsyncRegister.java | 3 +- .../authme/settings/CustomConfiguration.java | 3 +- .../fr/xephi/authme/settings/Settings.java | 3 +- .../authme/settings/custom/NewSetting.java | 3 +- .../java/fr/xephi/authme/util/GeoLiteAPI.java | 4 +- 15 files changed, 50 insertions(+), 77 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 1b39b3440..025c731e6 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -227,9 +227,7 @@ public class AuthMe extends JavaPlugin { try { setupDatabase(); } catch (Exception e) { - ConsoleLogger.writeStackTrace(e); - ConsoleLogger.showError(e.getMessage()); - ConsoleLogger.showError("Fatal error occurred during database connection! Authme initialization ABORTED!"); + ConsoleLogger.writeStackTrace(e.getMessage() + "\nFatal error occurred during database connection! Authme initialization ABORTED!" , e); stopOrUnload(); return; } @@ -452,9 +450,8 @@ public class AuthMe extends JavaPlugin { settings = new Settings(this); Settings.reload(); } catch (Exception e) { - ConsoleLogger.writeStackTrace(e); - ConsoleLogger.showError("Can't load the configuration file... Something went wrong. " - + "To avoid security issues the server will shut down!"); + ConsoleLogger.writeStackTrace("Can't load the configuration file... Something went wrong. " + + "To avoid security issues the server will shut down!", e); server.shutdown(); return true; } @@ -516,8 +513,7 @@ public class AuthMe extends JavaPlugin { ConsoleLogger.info("Metrics started successfully!"); } catch (Exception e) { // Failed to submit the metrics data - ConsoleLogger.writeStackTrace(e); - ConsoleLogger.showError("Can't start Metrics! The plugin will work anyway..."); + ConsoleLogger.writeStackTrace("Can't start Metrics! The plugin will work anyway...", e); } } diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index fee14296d..6256bc386 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -74,10 +74,11 @@ public final class ConsoleLogger { * * @param ex Exception */ - public static void writeStackTrace(Exception ex) { + public static void writeStackTrace(String message , Throwable ex) { if (!Settings.useLogging) { return; } + writeLog(message); writeLog(Throwables.getStackTraceAsString(ex)); } } 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 7e4ad2b19..28a08cb73 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 @@ -26,8 +26,7 @@ public class ReloadCommand implements ExecutableCommand { plugin.setupDatabase(); } catch (Exception e) { sender.sendMessage("Error occurred during reload of AuthMe: aborting"); - ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!"); - ConsoleLogger.writeStackTrace(e); + ConsoleLogger.writeStackTrace("Fatal error occurred! AuthMe instance ABORTED!", e); plugin.stopOrUnload(); } diff --git a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java index 5e85ce6ed..3159937a3 100644 --- a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java +++ b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java @@ -33,8 +33,7 @@ public class RoyalAuthConverter implements Converter { PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com", o.getName()); data.saveAuth(auth); } catch (Exception e) { - ConsoleLogger.writeStackTrace(e); - ConsoleLogger.showError("Error while trying to import " + o.getName() + " RoyalAuth datas"); + ConsoleLogger.writeStackTrace("Error while trying to import " + o.getName() + " RoyalAuth datas", e); } } } diff --git a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java index 16b89e5ac..f0aa197e9 100644 --- a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java +++ b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java @@ -53,7 +53,7 @@ class vAuthFileReader { } scanner.close(); } catch (Exception e) { - ConsoleLogger.writeStackTrace(e); + ConsoleLogger.writeStackTrace("Error while trying to import some vAuth datas", e); } } diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index e573c6d04..bec25c85b 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -172,7 +172,7 @@ public class CacheDataSource implements DataSource { exec.shutdown(); exec.awaitTermination(8, TimeUnit.SECONDS); } catch (InterruptedException e) { - ConsoleLogger.writeStackTrace(e); + ConsoleLogger.writeStackTrace("Error while closing CacheDataSource.", e); } source.close(); } diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 3c48c6da0..de1837696 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -257,8 +257,7 @@ public class MySQL implements DataSource { ResultSet rs = pst.executeQuery(); return rs.next(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return false; } @@ -276,8 +275,7 @@ public class MySQL implements DataSource { !columnSalt.isEmpty() ? rs.getString(columnSalt) : null); } } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return null; } @@ -322,8 +320,7 @@ public class MySQL implements DataSource { } } } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); return null; } return pAuth; @@ -525,8 +522,7 @@ public class MySQL implements DataSource { } return true; } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return false; } @@ -589,8 +585,7 @@ public class MySQL implements DataSource { } return true; } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return false; } @@ -623,8 +618,7 @@ public class MySQL implements DataSource { pst.setLong(1, until); result = pst.executeUpdate(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return result; } @@ -647,8 +641,7 @@ public class MySQL implements DataSource { st.executeUpdate(); st.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return list; } @@ -680,8 +673,7 @@ public class MySQL implements DataSource { pst.executeUpdate(); return true; } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return false; } @@ -702,8 +694,7 @@ public class MySQL implements DataSource { pst.close(); return true; } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return false; } @@ -722,8 +713,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return countIp; } @@ -739,8 +729,7 @@ public class MySQL implements DataSource { pst.close(); return true; } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return false; } @@ -750,9 +739,8 @@ public class MySQL implements DataSource { try { reloadArguments(); } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL configuration!"); - ConsoleLogger.writeStackTrace(ex); AuthMe.getInstance().stopOrUnload(); } } @@ -778,8 +766,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return result; } @@ -798,8 +785,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return result; } @@ -818,8 +804,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return countEmail; } @@ -834,8 +819,7 @@ public class MySQL implements DataSource { } pst.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } } @@ -854,8 +838,7 @@ public class MySQL implements DataSource { ResultSet rs = pst.executeQuery(); isLogged = rs.next() && (rs.getInt(columnLogged) == 1); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return isLogged; } @@ -870,8 +853,7 @@ public class MySQL implements DataSource { pst.executeUpdate(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } } @@ -885,8 +867,7 @@ public class MySQL implements DataSource { pst.executeUpdate(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } } @@ -900,8 +881,7 @@ public class MySQL implements DataSource { pst.executeUpdate(); pst.close(); } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } } @@ -917,8 +897,7 @@ public class MySQL implements DataSource { rs.close(); st.close(); } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return result; } @@ -932,8 +911,7 @@ public class MySQL implements DataSource { pst.setString(2, oldOne); pst.executeUpdate(); } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } } @@ -978,8 +956,7 @@ public class MySQL implements DataSource { rs.close(); st.close(); } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return auths; } @@ -1022,8 +999,7 @@ public class MySQL implements DataSource { auths.add(pAuth); } } catch (Exception ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } return auths; } diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 9b14b1cc0..bab5cf988 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -170,8 +170,7 @@ public class SQLite implements DataSource { !columnSalt.isEmpty() ? rs.getString(columnSalt) : null); } } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - ConsoleLogger.writeStackTrace(ex); + ConsoleLogger.writeStackTrace(ex.getMessage(), ex); } finally { close(rs); close(pst); diff --git a/src/main/java/fr/xephi/authme/modules/ModuleManager.java b/src/main/java/fr/xephi/authme/modules/ModuleManager.java index 23aa37a88..b2e8c9716 100644 --- a/src/main/java/fr/xephi/authme/modules/ModuleManager.java +++ b/src/main/java/fr/xephi/authme/modules/ModuleManager.java @@ -135,8 +135,7 @@ public class ModuleManager { } } catch (Exception ex) { - ConsoleLogger.writeStackTrace(ex); - ConsoleLogger.showError("Cannot load " + pathToJar.getName() + " jar file !"); + ConsoleLogger.writeStackTrace("Cannot load " + pathToJar.getName() + " jar file !", ex); } finally { try { if (jarFile != null) { diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java index 236c8cd49..5a8133b79 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java @@ -49,6 +49,13 @@ public class ProcessSyncronousPlayerLogout implements Runnable { player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); } + protected void restoreSpeedEffect() { + if (Settings.isRemoveSpeedEnabled) { + player.setWalkSpeed(0.0F); + player.setFlySpeed(0.0F); + } + } + /** * Method run. * @@ -77,6 +84,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable { if (Settings.applyBlindEffect) player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); player.setOp(false); + restoreSpeedEffect(); // Player is now logout... Time to fire event ! Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player)); if (Settings.bungee) diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index d1b1f900d..886b2b949 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -81,8 +81,7 @@ public class AsyncRegister { passwordRegister(); } } catch (Exception e) { - ConsoleLogger.showError(e.getMessage()); - ConsoleLogger.writeStackTrace(e); + ConsoleLogger.writeStackTrace(e.getMessage(), e); m.send(player, MessageKey.ERROR); } } diff --git a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java index cb1719cb1..0aab1c801 100644 --- a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java +++ b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java @@ -77,8 +77,7 @@ public abstract class CustomConfiguration extends YamlConfiguration { return true; } } catch (Exception e) { - ConsoleLogger.writeStackTrace(e); - ConsoleLogger.showError("Failed to load config from JAR"); + ConsoleLogger.writeStackTrace("Failed to load config from JAR", e); } } return false; diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 3fa437545..88d5a5fa8 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -313,8 +313,7 @@ public final class Settings { try { return Files.toString(EMAIL_FILE, Charsets.UTF_8); } catch (IOException e) { - ConsoleLogger.showError("Error loading email text: " + StringUtils.formatException(e)); - ConsoleLogger.writeStackTrace(e); + ConsoleLogger.writeStackTrace("Error loading email text: " + StringUtils.formatException(e), e); return ""; } } diff --git a/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java b/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java index 6f9abdc44..c6db84541 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java +++ b/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java @@ -129,8 +129,7 @@ public class NewSetting { writer.flush(); writer.close(); } catch (IOException e) { - ConsoleLogger.showError("Could not save config file - " + StringUtils.formatException(e)); - ConsoleLogger.writeStackTrace(e); + ConsoleLogger.writeStackTrace("Could not save config file - " + StringUtils.formatException(e), e); } } diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index ebd0deb31..4e396557d 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -36,7 +36,7 @@ public class GeoLiteAPI { plugin.getLogger().info(LICENSE); return true; } catch (IOException e) { - // TODO ljacqu 20151123: Log the exception instead of just swallowing it + ConsoleLogger.writeStackTrace("Could not find/download GeoLiteAPI", e); return false; } } @@ -63,7 +63,7 @@ public class GeoLiteAPI { output.close(); input.close(); } catch (IOException e) { - ConsoleLogger.writeStackTrace(e); + ConsoleLogger.writeStackTrace("Could not download GeoLiteAPI", e); } } }); From 05aec0f4fe7dfc6ffe7132e3be4f18fa2f7b61c0 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Fri, 5 Feb 2016 23:18:35 +0700 Subject: [PATCH 07/18] - Removed code for waiting Bukkit tasks to complete. --- src/main/java/fr/xephi/authme/AuthMe.java | 34 ----------------------- 1 file changed, 34 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 025c731e6..8fd97b857 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -533,40 +533,6 @@ public class AuthMe extends JavaPlugin { moduleManager.unloadModules(); } - List pendingTasks = getServer().getScheduler().getPendingTasks(); - for (Iterator iterator = pendingTasks.iterator(); iterator.hasNext();) { - BukkitTask pendingTask = iterator.next(); - if (!pendingTask.getOwner().equals(this) || pendingTask.isSync()) { - //remove all unrelevant tasks - iterator.remove(); - } - } - - getLogger().log(Level.INFO, "Waiting for {0} tasks to finish", pendingTasks.size()); - int progress = 0; - try { - for (BukkitTask pendingTask : pendingTasks) { - int maxTries = 5; - int taskId = pendingTask.getTaskId(); - while (getServer().getScheduler().isCurrentlyRunning(taskId)) { - if (maxTries <= 0) { - getLogger().log(Level.INFO, "Async task {0} times out after to many tries", taskId); - break; - } - - //one second - Thread.sleep(1000); - maxTries--; - } - - progress++; - getLogger().log(Level.INFO, "Progress: {0} / {1}", new Object[]{progress, pendingTasks.size()}); - } - } catch (InterruptedException interruptedException) { - - } - - // Close the database if (database != null) { database.close(); From c9b884624d9d61a21e7a986e29a4cab7bdf529c0 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Fri, 5 Feb 2016 23:26:46 +0700 Subject: [PATCH 08/18] - Make cache RemovalListener sync (no longer use executor). - Fix #433 --- .../java/fr/xephi/authme/datasource/CacheDataSource.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index bec25c85b..d27dbc922 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -34,9 +34,9 @@ public class CacheDataSource implements DataSource { public CacheDataSource(DataSource src) { this.source = src; this.exec = Executors.newCachedThreadPool(); - cachedAuths = CacheBuilder.newBuilder() - .expireAfterWrite(5, TimeUnit.MINUTES) - .removalListener(RemovalListeners.asynchronous(new RemovalListener>() { + this.cachedAuths = CacheBuilder.newBuilder() + .expireAfterWrite(8, TimeUnit.MINUTES) + .removalListener(new RemovalListener>() { @Override public void onRemoval(RemovalNotification> removalNotification) { String name = removalNotification.getKey(); @@ -44,7 +44,7 @@ public class CacheDataSource implements DataSource { cachedAuths.getUnchecked(name); } } - }, exec)) + }) .build( new CacheLoader>() { public Optional load(String key) { From ef89ab02b4b931485f751fd2951905f0a6e77da6 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Fri, 5 Feb 2016 23:27:34 +0700 Subject: [PATCH 09/18] Cleanup imports. --- src/main/java/fr/xephi/authme/datasource/CacheDataSource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index d27dbc922..305be039f 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -5,7 +5,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalListeners; import com.google.common.cache.RemovalNotification; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; From 190b4c2c2e31227a5ff0676cf1eeae6f22d5c0bf Mon Sep 17 00:00:00 2001 From: DNx5 Date: Sat, 6 Feb 2016 00:53:43 +0700 Subject: [PATCH 10/18] - Removed executor service and all uses from CachedDataSource. --- .../authme/datasource/CacheDataSource.java | 63 ++++--------------- 1 file changed, 11 insertions(+), 52 deletions(-) diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 305be039f..e66c5cd21 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -6,15 +6,12 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; -import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.security.crypts.HashedPassword; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; /** @@ -22,7 +19,6 @@ import java.util.concurrent.TimeUnit; public class CacheDataSource implements DataSource { private final DataSource source; - private final ExecutorService exec; private final LoadingCache> cachedAuths; /** @@ -32,7 +28,6 @@ public class CacheDataSource implements DataSource { */ public CacheDataSource(DataSource src) { this.source = src; - this.exec = Executors.newCachedThreadPool(); this.cachedAuths = CacheBuilder.newBuilder() .expireAfterWrite(8, TimeUnit.MINUTES) .removalListener(new RemovalListener>() { @@ -167,24 +162,13 @@ public class CacheDataSource implements DataSource { @Override public synchronized void close() { - try { - exec.shutdown(); - exec.awaitTermination(8, TimeUnit.SECONDS); - } catch (InterruptedException e) { - ConsoleLogger.writeStackTrace("Error while closing CacheDataSource.", e); - } source.close(); } @Override public void reload() { // unused method - exec.execute(new Runnable() { - @Override - public void run() { - source.reload(); - cachedAuths.invalidateAll(); - } - }); + source.reload(); + cachedAuths.invalidateAll(); } @Override @@ -213,13 +197,8 @@ public class CacheDataSource implements DataSource { @Override public synchronized void purgeBanned(final List banned) { - exec.execute(new Runnable() { - @Override - public void run() { - source.purgeBanned(banned); - cachedAuths.invalidateAll(banned); - } - }); + source.purgeBanned(banned); + cachedAuths.invalidateAll(banned); } @Override @@ -234,33 +213,18 @@ public class CacheDataSource implements DataSource { @Override public void setLogged(final String user) { - exec.execute(new Runnable() { - @Override - public void run() { - source.setLogged(user.toLowerCase()); - } - }); + source.setLogged(user.toLowerCase()); } @Override public void setUnlogged(final String user) { - exec.execute(new Runnable() { - @Override - public void run() { - source.setUnlogged(user.toLowerCase()); - } - }); + source.setUnlogged(user.toLowerCase()); } @Override public void purgeLogged() { - exec.execute(new Runnable() { - @Override - public void run() { - source.purgeLogged(); - cachedAuths.invalidateAll(); - } - }); + source.purgeLogged(); + cachedAuths.invalidateAll(); } @Override @@ -269,14 +233,9 @@ public class CacheDataSource implements DataSource { } @Override - public void updateName(final String oldOne, final String newOne) { - exec.execute(new Runnable() { - @Override - public void run() { - source.updateName(oldOne, newOne); - cachedAuths.invalidate(oldOne); - } - }); + public void updateName(final String oldOne, final String newOne) { // unused method + source.updateName(oldOne, newOne); + cachedAuths.invalidate(oldOne); } @Override From bd3761ad13cb50c2a1b22514030f2d5204206a0f Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 5 Feb 2016 19:34:54 +0100 Subject: [PATCH 11/18] Move metrics management to another class --- src/main/java/fr/xephi/authme/AuthMe.java | 94 ++++++------------- .../java/fr/xephi/authme/MetricsStarter.java | 45 +++++++++ 2 files changed, 74 insertions(+), 65 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/MetricsStarter.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 8fd97b857..82bf4ee9a 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -1,9 +1,35 @@ package fr.xephi.authme; -import com.earth2me.essentials.Essentials; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Logger; + import com.google.common.base.Charsets; import com.google.common.io.Resources; +import org.apache.logging.log4j.LogManager; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; + +import com.earth2me.essentials.Essentials; import com.onarandombox.MultiverseCore.MultiverseCore; +import net.minelink.ctplus.CombatTagPlus; + import fr.xephi.authme.api.API; import fr.xephi.authme.api.NewAPI; import fr.xephi.authme.cache.auth.PlayerAuth; @@ -53,33 +79,6 @@ import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Wrapper; -import net.minelink.ctplus.CombatTagPlus; -import org.apache.logging.log4j.LogManager; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitTask; -import org.mcstats.Metrics; -import org.mcstats.Metrics.Graph; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; /** * The AuthMe main class. @@ -245,9 +244,9 @@ public class AuthMe extends JavaPlugin { // Setup otherAccounts file this.otherAccounts = OtherAccounts.getInstance(); - // Set up Metrics - setupMetrics(); + final MetricsStarter metrics = new MetricsStarter(this); + metrics.setupMetrics(); // Set console filter setupConsoleFilter(); @@ -482,41 +481,6 @@ public class AuthMe extends JavaPlugin { } } - /** - * Set up Metrics. - */ - private void setupMetrics() { - try { - Metrics metrics = new Metrics(this); - Graph messagesLanguage = metrics.createGraph("Messages language"); - Graph databaseBackend = metrics.createGraph("Database backend"); - - // Custom graphs - if (Settings.messageFile.exists()) { - messagesLanguage.addPlotter(new Metrics.Plotter(Settings.messagesLanguage) { - - @Override - public int getValue() { - return 1; - } - }); - } - databaseBackend.addPlotter(new Metrics.Plotter(Settings.getDataSource.toString()) { - - @Override - public int getValue() { - return 1; - } - }); - - metrics.start(); - ConsoleLogger.info("Metrics started successfully!"); - } catch (Exception e) { - // Failed to submit the metrics data - ConsoleLogger.writeStackTrace("Can't start Metrics! The plugin will work anyway...", e); - } - } - @Override public void onDisable() { // Save player data diff --git a/src/main/java/fr/xephi/authme/MetricsStarter.java b/src/main/java/fr/xephi/authme/MetricsStarter.java new file mode 100644 index 000000000..83f3bb511 --- /dev/null +++ b/src/main/java/fr/xephi/authme/MetricsStarter.java @@ -0,0 +1,45 @@ +package fr.xephi.authme; + +import java.io.IOException; + +import org.mcstats.Metrics; +import org.mcstats.Metrics.Graph; + +import fr.xephi.authme.settings.Settings; + +public class MetricsStarter { + + public AuthMe plugin; + + public MetricsStarter(final AuthMe plugin) { + this.plugin = plugin; + } + + public void setupMetrics() { + try { + final Metrics metrics = new Metrics(plugin); + + final Graph messagesLanguage = metrics.createGraph("Messages Language"); + messagesLanguage.addPlotter(new Metrics.Plotter(Settings.messagesLanguage) { + @Override + public int getValue() { + return 1; + } + }); + + final Graph databaseBackend = metrics.createGraph("Database Backend"); + databaseBackend.addPlotter(new Metrics.Plotter(Settings.getDataSource.toString()) { + @Override + public int getValue() { + return 1; + } + }); + + // Submit metrics + metrics.start(); + } catch (final IOException e) { + // Failed to submit the metrics data + ConsoleLogger.writeStackTrace("Can't start Metrics! The plugin will work anyway...", e); + } + } +} From f6837bb33a4e6835d64d82f7a23d5b2de6b390c0 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 5 Feb 2016 20:42:06 +0100 Subject: [PATCH 12/18] Try to fix circle artifacts, again --- circle.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 672011c2e..a1959c7b1 100644 --- a/circle.yml +++ b/circle.yml @@ -7,7 +7,8 @@ general: test: override: - mvn clean install -B - + post: + - cp ./target/AuthMeReloaded*.jar $CIRCLE_ARTIFACTS notify: webhooks: - url: https://webhooks.gitter.im/e/7b92ac1a1741748b26bf From f98deff41ae5c16eade6e6be753a21f69a87b6f6 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 5 Feb 2016 20:46:32 +0100 Subject: [PATCH 13/18] Whoops --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index a1959c7b1..d5d3317c8 100644 --- a/circle.yml +++ b/circle.yml @@ -8,7 +8,7 @@ test: override: - mvn clean install -B post: - - cp ./target/AuthMeReloaded*.jar $CIRCLE_ARTIFACTS + - cp ./target/AuthMe*.jar $CIRCLE_ARTIFACTS notify: webhooks: - url: https://webhooks.gitter.im/e/7b92ac1a1741748b26bf From 717d455a8dfcfab19397716845fdd8b52d7e167d Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 5 Feb 2016 21:14:45 +0100 Subject: [PATCH 14/18] Provide also a jar without version number --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index d5d3317c8..37d8fb329 100644 --- a/circle.yml +++ b/circle.yml @@ -9,6 +9,7 @@ test: - mvn clean install -B post: - cp ./target/AuthMe*.jar $CIRCLE_ARTIFACTS + - cp ./target/AuthMe-*-SNAPSHOT.jar $CIRCLE_ARTIFACTS/AuthMe.java notify: webhooks: - url: https://webhooks.gitter.im/e/7b92ac1a1741748b26bf From 6495cee079dc656b50be4ba61523be32dbdf4d15 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 5 Feb 2016 21:19:12 +0100 Subject: [PATCH 15/18] Add alternative dev build download link! --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index da3267fbe..d648a6bcc 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ - Build status: [![Build Status](https://travis-ci.org/Xephi/AuthMeReloaded.svg?branch=master)](https://travis-ci.org/Xephi/AuthMeReloaded) [![Dependency Status](https://www.versioneye.com/user/projects/55bab9e8653762002000190a/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55bab9e8653762002000190a) - Build status (CircleCI): [![Circle CI](https://circleci.com/gh/Xephi/AuthMeReloaded.svg?style=svg)](https://circleci.com/gh/Xephi/AuthMeReloaded) +- Alternative Dev Build download link (via CircleCi): Download - Code Coverage: [![Coverage Status](https://coveralls.io/repos/AuthMe-Team/AuthMeReloaded/badge.svg?branch=master&service=github)](https://coveralls.io/github/AuthMe-Team/AuthMeReloaded?branch=master) From 558cbf58480d0290d228044ef991fbd7b6d5d3b4 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Fri, 5 Feb 2016 21:20:15 +0100 Subject: [PATCH 16/18] Really? -_- --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 37d8fb329..da709f387 100644 --- a/circle.yml +++ b/circle.yml @@ -9,7 +9,7 @@ test: - mvn clean install -B post: - cp ./target/AuthMe*.jar $CIRCLE_ARTIFACTS - - cp ./target/AuthMe-*-SNAPSHOT.jar $CIRCLE_ARTIFACTS/AuthMe.java + - cp ./target/AuthMe-*-SNAPSHOT.jar $CIRCLE_ARTIFACTS/AuthMe.jar notify: webhooks: - url: https://webhooks.gitter.im/e/7b92ac1a1741748b26bf From c28a1b537f717c1af7b83bde85d1cd550559b90a Mon Sep 17 00:00:00 2001 From: ljacqu Date: Fri, 5 Feb 2016 23:09:07 +0100 Subject: [PATCH 17/18] #495 Create ConsoleLogger method dedicated to logging exceptions --- src/main/java/fr/xephi/authme/AuthMe.java | 13 ++-- .../java/fr/xephi/authme/ConsoleLogger.java | 30 +++++---- .../java/fr/xephi/authme/MetricsStarter.java | 2 +- .../executable/authme/ReloadCommand.java | 2 +- .../authme/converter/RoyalAuthConverter.java | 2 +- .../authme/converter/vAuthFileReader.java | 15 ++--- .../fr/xephi/authme/datasource/MySQL.java | 64 ++++++++++--------- .../fr/xephi/authme/datasource/SQLite.java | 2 +- .../xephi/authme/modules/ModuleManager.java | 2 +- .../process/register/AsyncRegister.java | 2 +- .../authme/settings/CustomConfiguration.java | 2 +- .../fr/xephi/authme/settings/Settings.java | 7 +- .../authme/settings/custom/NewSetting.java | 2 +- .../java/fr/xephi/authme/util/GeoLiteAPI.java | 4 +- 14 files changed, 78 insertions(+), 71 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 82bf4ee9a..23301b42c 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -212,7 +212,7 @@ public class AuthMe extends JavaPlugin { setPluginInfos(); // Load settings and custom configurations, if it fails, stop the server due to security reasons. - if (loadSettings()) { + if (!loadSettings()) { server.shutdown(); setEnabled(false); return; @@ -226,7 +226,8 @@ public class AuthMe extends JavaPlugin { try { setupDatabase(); } catch (Exception e) { - ConsoleLogger.writeStackTrace(e.getMessage() + "\nFatal error occurred during database connection! Authme initialization ABORTED!" , e); + ConsoleLogger.logException("Fatal error occurred during database connection! " + + "Authme initialization aborted!", e); stopOrUnload(); return; } @@ -448,11 +449,11 @@ public class AuthMe extends JavaPlugin { try { settings = new Settings(this); Settings.reload(); - } catch (Exception e) { - ConsoleLogger.writeStackTrace("Can't load the configuration file... Something went wrong. " - + "To avoid security issues the server will shut down!", e); - server.shutdown(); return true; + } catch (Exception e) { + ConsoleLogger.logException("Can't load the configuration file... Something went wrong. " + + "To avoid security issues the server will shut down!", e); + server.shutdown(); } return false; } diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index 6256bc386..c3a4bdc2f 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -2,6 +2,7 @@ package fr.xephi.authme; import com.google.common.base.Throwables; import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.Wrapper; import java.io.IOException; @@ -33,9 +34,8 @@ public final class ConsoleLogger { public static void info(String message) { wrapper.getLogger().info(message); if (!Settings.useLogging) { - return; + writeLog(message); } - writeLog("" + message); } /** @@ -45,10 +45,9 @@ public final class ConsoleLogger { */ public static void showError(String message) { wrapper.getLogger().warning(message); - if (!Settings.useLogging) { - return; + if (Settings.useLogging) { + writeLog("ERROR: " + message); } - writeLog("ERROR: " + message); } /** @@ -72,13 +71,22 @@ public final class ConsoleLogger { /** * Write a StackTrace into the log. * - * @param ex Exception + * @param th The Throwable whose stack trace should be logged */ - public static void writeStackTrace(String message , Throwable ex) { - if (!Settings.useLogging) { - return; + public static void writeStackTrace(Throwable th) { + if (Settings.useLogging) { + writeLog(Throwables.getStackTraceAsString(th)); } - writeLog(message); - writeLog(Throwables.getStackTraceAsString(ex)); + } + + /** + * Logs a Throwable with the provided message and saves the stack trace to the log file. + * + * @param message The message to accompany the exception + * @param th The Throwable to log + */ + public static void logException(String message, Throwable th) { + showError(message + " " + StringUtils.formatException(th)); + writeStackTrace(th); } } diff --git a/src/main/java/fr/xephi/authme/MetricsStarter.java b/src/main/java/fr/xephi/authme/MetricsStarter.java index 83f3bb511..8fb0e498b 100644 --- a/src/main/java/fr/xephi/authme/MetricsStarter.java +++ b/src/main/java/fr/xephi/authme/MetricsStarter.java @@ -39,7 +39,7 @@ public class MetricsStarter { metrics.start(); } catch (final IOException e) { // Failed to submit the metrics data - ConsoleLogger.writeStackTrace("Can't start Metrics! The plugin will work anyway...", e); + ConsoleLogger.logException("Can't start Metrics! The plugin will work anyway...", e); } } } 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 28a08cb73..875802a64 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 @@ -26,7 +26,7 @@ public class ReloadCommand implements ExecutableCommand { plugin.setupDatabase(); } catch (Exception e) { sender.sendMessage("Error occurred during reload of AuthMe: aborting"); - ConsoleLogger.writeStackTrace("Fatal error occurred! AuthMe instance ABORTED!", e); + ConsoleLogger.logException("Aborting! Encountered exception during reload of AuthMe:", e); plugin.stopOrUnload(); } diff --git a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java index 3159937a3..42bd681df 100644 --- a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java +++ b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java @@ -33,7 +33,7 @@ public class RoyalAuthConverter implements Converter { PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com", o.getName()); data.saveAuth(auth); } catch (Exception e) { - ConsoleLogger.writeStackTrace("Error while trying to import " + o.getName() + " RoyalAuth datas", e); + ConsoleLogger.logException("Error while trying to import " + o.getName() + " RoyalAuth data", e); } } } diff --git a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java index f0aa197e9..bb25b04bd 100644 --- a/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java +++ b/src/main/java/fr/xephi/authme/converter/vAuthFileReader.java @@ -8,6 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import java.io.File; +import java.io.IOException; import java.util.Scanner; import java.util.UUID; @@ -27,7 +28,7 @@ class vAuthFileReader { } public void convert() { - final File file = new File(plugin.getDataFolder().getParent() + "" + File.separator + "vAuth" + File.separator + "passwords.yml"); + final File file = new File(plugin.getDataFolder().getParent() + File.separator + "vAuth" + File.separator + "passwords.yml"); Scanner scanner; try { scanner = new Scanner(file); @@ -52,8 +53,8 @@ class vAuthFileReader { database.saveAuth(auth); } scanner.close(); - } catch (Exception e) { - ConsoleLogger.writeStackTrace("Error while trying to import some vAuth datas", e); + } catch (IOException e) { + ConsoleLogger.logException("Error while trying to import some vAuth data", e); } } @@ -63,12 +64,10 @@ class vAuthFileReader { } private String getName(UUID uuid) { - try { - for (OfflinePlayer op : Bukkit.getOfflinePlayers()) { - if (op.getUniqueId().compareTo(uuid) == 0) - return op.getName(); + for (OfflinePlayer op : Bukkit.getOfflinePlayers()) { + if (op.getUniqueId().compareTo(uuid) == 0) { + return op.getName(); } - } catch (Exception ignored) { } return null; } diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index de1837696..03da26d3d 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -257,7 +257,7 @@ public class MySQL implements DataSource { ResultSet rs = pst.executeQuery(); return rs.next(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return false; } @@ -275,7 +275,7 @@ public class MySQL implements DataSource { !columnSalt.isEmpty() ? rs.getString(columnSalt) : null); } } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return null; } @@ -320,7 +320,7 @@ public class MySQL implements DataSource { } } } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); return null; } return pAuth; @@ -522,7 +522,7 @@ public class MySQL implements DataSource { } return true; } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return false; } @@ -585,7 +585,7 @@ public class MySQL implements DataSource { } return true; } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return false; } @@ -618,7 +618,7 @@ public class MySQL implements DataSource { pst.setLong(1, until); result = pst.executeUpdate(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return result; } @@ -641,7 +641,7 @@ public class MySQL implements DataSource { st.executeUpdate(); st.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return list; } @@ -673,7 +673,7 @@ public class MySQL implements DataSource { pst.executeUpdate(); return true; } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return false; } @@ -694,7 +694,7 @@ public class MySQL implements DataSource { pst.close(); return true; } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return false; } @@ -713,7 +713,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return countIp; } @@ -729,7 +729,7 @@ public class MySQL implements DataSource { pst.close(); return true; } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return false; } @@ -739,8 +739,8 @@ public class MySQL implements DataSource { try { reloadArguments(); } catch (Exception ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); - ConsoleLogger.showError("Can't reconnect to MySQL database... Please check your MySQL configuration!"); + ConsoleLogger.logException("Can't reconnect to MySQL database... " + + "Please check your MySQL configuration! Encountered", ex); AuthMe.getInstance().stopOrUnload(); } } @@ -766,7 +766,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return result; } @@ -785,7 +785,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return result; } @@ -804,7 +804,7 @@ public class MySQL implements DataSource { rs.close(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return countEmail; } @@ -819,7 +819,7 @@ public class MySQL implements DataSource { } pst.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } } @@ -838,7 +838,7 @@ public class MySQL implements DataSource { ResultSet rs = pst.executeQuery(); isLogged = rs.next() && (rs.getInt(columnLogged) == 1); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } return isLogged; } @@ -853,7 +853,7 @@ public class MySQL implements DataSource { pst.executeUpdate(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } } @@ -867,7 +867,7 @@ public class MySQL implements DataSource { pst.executeUpdate(); pst.close(); } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + logSqlException(ex); } } @@ -880,8 +880,8 @@ public class MySQL implements DataSource { pst.setInt(2, 1); pst.executeUpdate(); pst.close(); - } catch (Exception ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + } catch (SQLException ex) { + logSqlException(ex); } } @@ -896,8 +896,8 @@ public class MySQL implements DataSource { } rs.close(); st.close(); - } catch (Exception ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + } catch (SQLException ex) { + logSqlException(ex); } return result; } @@ -910,8 +910,8 @@ public class MySQL implements DataSource { pst.setString(1, newOne); pst.setString(2, oldOne); pst.executeUpdate(); - } catch (Exception ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + } catch (SQLException ex) { + logSqlException(ex); } } @@ -955,8 +955,8 @@ public class MySQL implements DataSource { pst.close(); rs.close(); st.close(); - } catch (Exception ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + } catch (SQLException ex) { + logSqlException(ex); } return auths; } @@ -998,10 +998,14 @@ public class MySQL implements DataSource { } auths.add(pAuth); } - } catch (Exception ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + } catch (SQLException ex) { + logSqlException(ex); } return auths; } + private static void logSqlException(SQLException e) { + ConsoleLogger.logException("Error during SQL operation:", e); + } + } diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index bab5cf988..ca9c2565c 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -170,7 +170,7 @@ public class SQLite implements DataSource { !columnSalt.isEmpty() ? rs.getString(columnSalt) : null); } } catch (SQLException ex) { - ConsoleLogger.writeStackTrace(ex.getMessage(), ex); + ConsoleLogger.logException("Error getting password:", ex); } finally { close(rs); close(pst); diff --git a/src/main/java/fr/xephi/authme/modules/ModuleManager.java b/src/main/java/fr/xephi/authme/modules/ModuleManager.java index b2e8c9716..6228091c2 100644 --- a/src/main/java/fr/xephi/authme/modules/ModuleManager.java +++ b/src/main/java/fr/xephi/authme/modules/ModuleManager.java @@ -135,7 +135,7 @@ public class ModuleManager { } } catch (Exception ex) { - ConsoleLogger.writeStackTrace("Cannot load " + pathToJar.getName() + " jar file !", ex); + ConsoleLogger.logException("Cannot load " + pathToJar.getName() + " jar file!", ex); } finally { try { if (jarFile != null) { diff --git a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java index 886b2b949..6ef2bf24a 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -81,7 +81,7 @@ public class AsyncRegister { passwordRegister(); } } catch (Exception e) { - ConsoleLogger.writeStackTrace(e.getMessage(), e); + ConsoleLogger.logException("Error during async register process", e); m.send(player, MessageKey.ERROR); } } diff --git a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java index 0aab1c801..ee1645257 100644 --- a/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java +++ b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java @@ -77,7 +77,7 @@ public abstract class CustomConfiguration extends YamlConfiguration { return true; } } catch (Exception e) { - ConsoleLogger.writeStackTrace("Failed to load config from JAR", e); + ConsoleLogger.logException("Failed to load config from JAR", e); } } return false; diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 88d5a5fa8..e38fd9f8d 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -313,7 +313,7 @@ public final class Settings { try { return Files.toString(EMAIL_FILE, Charsets.UTF_8); } catch (IOException e) { - ConsoleLogger.writeStackTrace("Error loading email text: " + StringUtils.formatException(e), e); + ConsoleLogger.logException("Error loading email text:", e); return ""; } } @@ -748,11 +748,6 @@ public final class Settings { } } - /** - * @param path - * - * @return - */ private static boolean contains(String path) { return configFile.contains(path); } diff --git a/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java b/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java index c6db84541..7a9094f61 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java +++ b/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java @@ -129,7 +129,7 @@ public class NewSetting { writer.flush(); writer.close(); } catch (IOException e) { - ConsoleLogger.writeStackTrace("Could not save config file - " + StringUtils.formatException(e), e); + ConsoleLogger.logException("Could not save config file:", e); } } diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index 4e396557d..7f519a779 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -36,7 +36,7 @@ public class GeoLiteAPI { plugin.getLogger().info(LICENSE); return true; } catch (IOException e) { - ConsoleLogger.writeStackTrace("Could not find/download GeoLiteAPI", e); + ConsoleLogger.logException("Could not find/download GeoLiteAPI", e); return false; } } @@ -63,7 +63,7 @@ public class GeoLiteAPI { output.close(); input.close(); } catch (IOException e) { - ConsoleLogger.writeStackTrace("Could not download GeoLiteAPI", e); + ConsoleLogger.logException("Could not download GeoLiteAPI", e); } } }); From a103aee4da8bd0010e17bff09edb3e7124ef2df8 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Fri, 5 Feb 2016 23:13:09 +0100 Subject: [PATCH 18/18] Addendum - only write to log if specified by settings - Commit forgotten removal of `!` during refactoring --- src/main/java/fr/xephi/authme/ConsoleLogger.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index c3a4bdc2f..605cabc08 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -33,7 +33,7 @@ public final class ConsoleLogger { */ public static void info(String message) { wrapper.getLogger().info(message); - if (!Settings.useLogging) { + if (Settings.useLogging) { writeLog(message); } }