From 4f76398ce860b4fc68fa2b6dac9b31d999bb7c7c Mon Sep 17 00:00:00 2001 From: Xephi Date: Fri, 5 Feb 2016 13:24:38 +0100 Subject: [PATCH] #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); } } });