From 2de0e0e819f30ad0724e5e7955d847b333a75955 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Thu, 26 Nov 2015 08:17:19 +0700 Subject: [PATCH] Set classes to use Messages getter in plugin instance. --- src/main/java/fr/xephi/authme/AuthMe.java | 4 ++-- .../executable/authme/AccountsCommand.java | 2 +- .../executable/authme/ChangePasswordCommand.java | 5 ++--- .../executable/authme/GetEmailCommand.java | 2 +- .../executable/authme/LastLoginCommand.java | 2 +- .../authme/PurgeLastPositionCommand.java | 2 +- .../executable/authme/RegisterCommand.java | 2 +- .../command/executable/authme/ReloadCommand.java | 4 ++-- .../executable/authme/SetEmailCommand.java | 2 +- .../executable/authme/UnregisterCommand.java | 2 +- .../executable/captcha/CaptchaCommand.java | 7 ++++--- .../changepassword/ChangePasswordCommand.java | 16 +++++++++++----- .../executable/converter/ConverterCommand.java | 2 +- .../executable/email/RecoverEmailCommand.java | 2 +- .../executable/register/RegisterCommand.java | 12 +++++++----- .../executable/unregister/UnregisterCommand.java | 2 +- .../fr/xephi/authme/converter/SqlToFlat.java | 2 +- .../authme/listener/AuthMePlayerListener.java | 3 ++- .../authme/listener/AuthMeServerListener.java | 5 +++-- .../authme/process/email/AsyncChangeEmail.java | 2 +- .../authme/process/join/AsynchronousJoin.java | 2 +- .../authme/process/login/AsynchronousLogin.java | 10 +++++----- .../process/logout/AsynchronousLogout.java | 6 +++--- .../logout/ProcessSyncronousPlayerLogout.java | 3 ++- .../authme/process/register/AsyncRegister.java | 8 ++++---- .../register/ProcessSyncEmailRegister.java | 3 ++- .../ProcessSyncronousPasswordRegister.java | 3 ++- .../unregister/AsynchronousUnregister.java | 8 ++++---- .../java/fr/xephi/authme/settings/Messages.java | 1 + .../fr/xephi/authme/task/ChangePasswordTask.java | 2 +- .../java/fr/xephi/authme/task/TimeoutTask.java | 10 ++++++---- 31 files changed, 76 insertions(+), 60 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index fe492ff59..1ad433a2a 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -221,7 +221,7 @@ public class AuthMe extends JavaPlugin { this.otherAccounts = OtherAccounts.getInstance(); // Setup messages - this.messages = Messages.getInstance(); + this.messages = new Messages(Settings.messageFile, Settings.messagesLanguage); // Set up Metrics setupMetrics(); @@ -902,7 +902,7 @@ public class AuthMe extends JavaPlugin { * * @return The real IP of the player. */ - // TODO: Cache the result + // TODO: Cache the result or run it async, it can cause trouble if verygames server isn't responding. @Deprecated public String getVeryGamesIp(Player player) { String realIP = player.getAddress().getAddress().getHostAddress(); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java index 135f54e02..6d8693e81 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java @@ -21,7 +21,7 @@ public class AccountsCommand extends ExecutableCommand { final AuthMe plugin = AuthMe.getInstance(); // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Get the player query String playerQuery = sender.getName(); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java index fffd7b960..fe96900aa 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordCommand.java @@ -20,8 +20,9 @@ public class ChangePasswordCommand extends ExecutableCommand { @Override public boolean executeCommand(final CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { + final AuthMe plugin = AuthMe.getInstance(); // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Get the player and password String playerName = commandArguments.get(0); @@ -47,9 +48,7 @@ public class ChangePasswordCommand extends ExecutableCommand { return true; } } - // Set the password - final AuthMe plugin = AuthMe.getInstance(); final String playerNameLowerCase = playerName.toLowerCase(); Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java index 5e484c755..5cfb4f033 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java @@ -29,7 +29,7 @@ public class GetEmailCommand extends ExecutableCommand { // Get the authenticated user AuthMe plugin = AuthMe.getInstance(); - Messages m = Messages.getInstance(); + Messages m = plugin.getMessages(); PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase()); if (auth == null) { m.send(sender, "unknown_user"); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java index 3e34f4d94..84fd210b9 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java @@ -22,7 +22,7 @@ public class LastLoginCommand extends ExecutableCommand { // Validate the player AuthMe plugin = AuthMe.getInstance(); - Messages m = Messages.getInstance(); + Messages m = plugin.getMessages(); PlayerAuth auth; try { diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java index 35b8734d0..24d4d93dd 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java @@ -28,7 +28,7 @@ public class PurgeLastPositionCommand extends ExecutableCommand { final AuthMe plugin = AuthMe.getInstance(); // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Get the player String playerName = sender.getName(); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java index 150255f65..afc265fcc 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterCommand.java @@ -32,7 +32,7 @@ public class RegisterCommand extends ExecutableCommand { final AuthMe plugin = AuthMe.getInstance(); // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Get the player name and password final String playerName = commandArguments.get(0); 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 e8b99d58d..56cb6680c 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 @@ -33,15 +33,15 @@ public class ReloadCommand extends ExecutableCommand { AuthMe plugin = AuthMe.getInstance(); // Messages instance - Messages m = Messages.getInstance(); + Messages m = plugin.getMessages(); // Show a status message // sender.sendMessage(ChatColor.YELLOW + "Reloading AuthMeReloaded..."); try { Settings.reload(); + plugin.setMessages(new Messages(Settings.messageFile, Settings.messagesLanguage)); plugin.getModuleManager().reloadModules(); - Messages.getInstance().reloadMessages(); plugin.setupDatabase(); } catch (Exception e) { ConsoleLogger.showError("Fatal error occurred! AuthMe instance ABORTED!"); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java index fbec1640d..11c5d75a9 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java @@ -28,7 +28,7 @@ public class SetEmailCommand extends ExecutableCommand { AuthMe plugin = AuthMe.getInstance(); // Messages instance - Messages m = Messages.getInstance(); + Messages m = plugin.getMessages(); // Get the player name and email address String playerName = commandArguments.get(0); diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java index ddf1c8ec0..f10116205 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterCommand.java @@ -39,7 +39,7 @@ public class UnregisterCommand extends ExecutableCommand { final AuthMe plugin = AuthMe.getInstance(); // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Get the player name String playerName = commandArguments.get(0); diff --git a/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java b/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java index bcf013efc..a5a194c62 100644 --- a/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/captcha/CaptchaCommand.java @@ -29,8 +29,11 @@ public class CaptchaCommand extends ExecutableCommand { // Get the parameter values String captcha = commandArguments.get(0); + // AuthMe plugin instance + final AuthMe plugin = AuthMe.getInstance(); + // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Command logic if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) { @@ -43,8 +46,6 @@ public class CaptchaCommand extends ExecutableCommand { return true; } - // AuthMe plugin instance - final AuthMe plugin = AuthMe.getInstance(); if (!plugin.cap.containsKey(playerNameLowerCase)) { m.send(player, MessageKey.USAGE_LOGIN); diff --git a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java index f8e7e23df..509bb3007 100644 --- a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java @@ -16,7 +16,8 @@ public class ChangePasswordCommand extends ExecutableCommand { @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - final Messages m = Messages.getInstance(); + final AuthMe plugin = AuthMe.getInstance(); + final Messages m = plugin.getMessages(); // Get the passwords String playerPass = commandArguments.get(0); @@ -37,7 +38,11 @@ public class ChangePasswordCommand extends ExecutableCommand { // Make sure the password is allowed String playerPassLowerCase = playerPass.toLowerCase(); - if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || !playerPassLowerCase.matches(Settings.getPassRegex)) { + if (playerPassLowerCase.contains("delete") || playerPassLowerCase.contains("where") + || playerPassLowerCase.contains("insert") || playerPassLowerCase.contains("modify") + || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") + || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") + || !playerPassLowerCase.matches(Settings.getPassRegex)) { m.send(player, "password_error"); return true; } @@ -45,7 +50,8 @@ public class ChangePasswordCommand extends ExecutableCommand { m.send(player, "password_error_nick"); return true; } - if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) { + if (playerPassLowerCase.length() < Settings.getPasswordMinLen + || playerPassLowerCase.length() > Settings.passwordMaxLength) { m.send(player, "pass_len"); return true; } @@ -57,8 +63,8 @@ public class ChangePasswordCommand extends ExecutableCommand { } // Set the password - final AuthMe plugin = AuthMe.getInstance(); - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new ChangePasswordTask(plugin, player, playerPass, playerPassVerify)); + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, + new ChangePasswordTask(plugin, player, playerPass, playerPassVerify)); return true; } } diff --git a/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java b/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java index cf8dd9dfa..3604f8421 100644 --- a/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/converter/ConverterCommand.java @@ -27,7 +27,7 @@ public class ConverterCommand extends ExecutableCommand { final AuthMe plugin = AuthMe.getInstance(); // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Get the conversion job String job = commandArguments.get(0); diff --git a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java index 2ac2b09e6..67f75c61d 100644 --- a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java @@ -35,7 +35,7 @@ public class RecoverEmailCommand extends ExecutableCommand { // Command logic final AuthMe plugin = AuthMe.getInstance(); - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); if (plugin.mail == null) { m.send(player, "error"); diff --git a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java index 657c33632..3fb45a51d 100644 --- a/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/register/RegisterCommand.java @@ -16,7 +16,6 @@ public class RegisterCommand extends ExecutableCommand { @Override public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { - final Messages m = Messages.getInstance(); // Make sure the sender is a player if (!(sender instanceof Player)) { @@ -24,6 +23,9 @@ public class RegisterCommand extends ExecutableCommand { return true; } + final AuthMe plugin = AuthMe.getInstance(); + final Messages m = plugin.getMessages(); + // Make sure the command arguments are valid final Player player = (Player) sender; if (commandArguments.getCount() == 0 || (Settings.getEnablePasswordVerifier && commandArguments.getCount() < 2)) { @@ -31,7 +33,7 @@ public class RegisterCommand extends ExecutableCommand { return true; } - final Management management = AuthMe.getInstance().getManagement(); + final Management management = plugin.getManagement(); if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { if (Settings.doubleEmailCheck) { if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) { @@ -44,16 +46,16 @@ public class RegisterCommand extends ExecutableCommand { m.send(player, "email_invalid"); return true; } - RandomString rand = new RandomString(Settings.getRecoveryPassLength); - final String thePass = rand.nextString(); + final String thePass = new RandomString(Settings.getRecoveryPassLength).nextString(); management.performRegister(player, thePass, email); return true; } - if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier) + if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier) { if (!commandArguments.get(0).equals(commandArguments.get(1))) { m.send(player, "password_error"); return true; } + } management.performRegister(player, commandArguments.get(0), ""); return true; } diff --git a/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java b/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java index dd5192ede..ece343c85 100644 --- a/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/unregister/UnregisterCommand.java @@ -27,7 +27,7 @@ public class UnregisterCommand extends ExecutableCommand { final AuthMe plugin = AuthMe.getInstance(); // Messages instance - final Messages m = Messages.getInstance(); + final Messages m = plugin.getMessages(); // Make sure the current command executor is a player if (!(sender instanceof Player)) { diff --git a/src/main/java/fr/xephi/authme/converter/SqlToFlat.java b/src/main/java/fr/xephi/authme/converter/SqlToFlat.java index 189cb8cf5..836486b89 100644 --- a/src/main/java/fr/xephi/authme/converter/SqlToFlat.java +++ b/src/main/java/fr/xephi/authme/converter/SqlToFlat.java @@ -52,7 +52,7 @@ public class SqlToFlat implements Converter { sender.sendMessage("Successfully convert from SQL table to file auths.db"); } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); - Messages.getInstance().send(sender, "error"); + plugin.getMessages().send(sender, "error"); } } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 644b13ab5..aa9b16422 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -40,7 +40,7 @@ public class AuthMePlayerListener implements Listener { public static final ConcurrentHashMap joinMessage = new ConcurrentHashMap<>(); public static final ConcurrentHashMap causeByAuthMe = new ConcurrentHashMap<>(); public final AuthMe plugin; - private final Messages m = Messages.getInstance(); + private final Messages m; /** * Constructor for AuthMePlayerListener. @@ -48,6 +48,7 @@ public class AuthMePlayerListener implements Listener { * @param plugin AuthMe */ public AuthMePlayerListener(AuthMe plugin) { + this.m = plugin.getMessages(); this.plugin = plugin; } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java index a5846e34e..0be77e935 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java @@ -17,8 +17,8 @@ import org.bukkit.plugin.Plugin; */ public class AuthMeServerListener implements Listener { - public final AuthMe plugin; - private final Messages m = Messages.getInstance(); + private final AuthMe plugin; + private final Messages m; /** * Constructor for AuthMeServerListener. @@ -26,6 +26,7 @@ public class AuthMeServerListener implements Listener { * @param plugin AuthMe */ public AuthMeServerListener(AuthMe plugin) { + this.m = plugin.getMessages(); this.plugin = plugin; } diff --git a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java index e7147dcec..c3836579d 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -23,12 +23,12 @@ public class AsyncChangeEmail { private final Messages m; public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, String newEmailVerify) { + this.m = plugin.getMessages(); this.player = player; this.plugin = plugin; this.oldEmail = oldEmail; this.newEmail = newEmail; this.newEmailVerify = newEmailVerify; - this.m = Messages.getInstance(); } public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail) { diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index f3604cdee..0be130e01 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -40,12 +40,12 @@ public class AsynchronousJoin { private final BukkitScheduler sched; public AsynchronousJoin(Player player, AuthMe plugin, DataSource database) { + this.m = plugin.getMessages(); this.player = player; this.plugin = plugin; this.sched = plugin.getServer().getScheduler(); this.database = database; this.name = player.getName().toLowerCase(); - this.m = Messages.getInstance(); } public void process() { diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 63d192a08..781dc60e6 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -33,7 +33,7 @@ public class AsynchronousLogin { protected final boolean forceLogin; private final AuthMe plugin; private final DataSource database; - private final Messages m = Messages.getInstance(); + private final Messages m; /** * Constructor for AsynchronousLogin. @@ -44,12 +44,12 @@ public class AsynchronousLogin { * @param plugin AuthMe * @param data DataSource */ - public AsynchronousLogin(Player player, String password, boolean forceLogin, - AuthMe plugin, DataSource data) { + public AsynchronousLogin(Player player, String password, boolean forceLogin, AuthMe plugin, DataSource data) { + this.m = plugin.getMessages(); this.player = player; + this.name = player.getName().toLowerCase(); this.password = password; - name = player.getName().toLowerCase(); - realName = player.getName(); + this.realName = player.getName(); this.forceLogin = forceLogin; this.plugin = plugin; this.database = data; diff --git a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java index d6642f0ee..79d2959ea 100644 --- a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java @@ -20,7 +20,7 @@ public class AsynchronousLogout { protected final AuthMe plugin; protected final DataSource database; protected boolean canLogout = true; - private final Messages m = Messages.getInstance(); + private final Messages m; /** * Constructor for AsynchronousLogout. @@ -29,8 +29,8 @@ public class AsynchronousLogout { * @param plugin AuthMe * @param database DataSource */ - public AsynchronousLogout(Player player, AuthMe plugin, - DataSource database) { + public AsynchronousLogout(Player player, AuthMe plugin, DataSource database) { + this.m = plugin.getMessages(); this.player = player; this.plugin = plugin; this.database = database; 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 9bf98aab6..76600c599 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java @@ -22,7 +22,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable { protected final Player player; protected final AuthMe plugin; protected final String name; - private final Messages m = Messages.getInstance(); + private final Messages m; /** * Constructor for ProcessSyncronousPlayerLogout. @@ -31,6 +31,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable { * @param plugin AuthMe */ public ProcessSyncronousPlayerLogout(Player player, AuthMe plugin) { + this.m = plugin.getMessages(); this.player = player; this.plugin = plugin; this.name = player.getName().toLowerCase(); 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 d66e1ca2e..f18f02c30 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -23,7 +23,7 @@ public class AsyncRegister { protected String email = ""; private final AuthMe plugin; private final DataSource database; - private final Messages m = Messages.getInstance(); + private final Messages m; /** * Constructor for AsyncRegister. @@ -34,11 +34,11 @@ public class AsyncRegister { * @param plugin AuthMe * @param data DataSource */ - public AsyncRegister(Player player, String password, String email, - AuthMe plugin, DataSource data) { + public AsyncRegister(Player player, String password, String email, AuthMe plugin, DataSource data) { + this.m = plugin.getMessages(); this.player = player; this.password = password; - name = player.getName().toLowerCase(); + this.name = player.getName().toLowerCase(); this.email = email; this.plugin = plugin; this.database = data; diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java index fc80d41c6..0a1fa59d4 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -20,7 +20,7 @@ public class ProcessSyncEmailRegister implements Runnable { protected final Player player; protected final String name; private final AuthMe plugin; - private final Messages m = Messages.getInstance(); + private final Messages m; /** * Constructor for ProcessSyncEmailRegister. @@ -29,6 +29,7 @@ public class ProcessSyncEmailRegister implements Runnable { * @param plugin AuthMe */ public ProcessSyncEmailRegister(Player player, AuthMe plugin) { + this.m = plugin.getMessages(); this.player = player; this.name = player.getName().toLowerCase(); this.plugin = plugin; diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java index d215ea003..0b188948a 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -25,7 +25,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { protected final Player player; protected final String name; private final AuthMe plugin; - private final Messages m = Messages.getInstance(); + private final Messages m; /** * Constructor for ProcessSyncronousPasswordRegister. @@ -34,6 +34,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { * @param plugin AuthMe */ public ProcessSyncronousPasswordRegister(Player player, AuthMe plugin) { + this.m = plugin.getMessages(); this.player = player; this.name = player.getName().toLowerCase(); this.plugin = plugin; diff --git a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java index 907333273..0f7cfaa29 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -29,7 +29,7 @@ public class AsynchronousUnregister { protected final String password; protected final boolean force; private final AuthMe plugin; - private final Messages m = Messages.getInstance(); + private final Messages m; private final JsonCache playerCache; /** @@ -40,12 +40,12 @@ public class AsynchronousUnregister { * @param force boolean * @param plugin AuthMe */ - public AsynchronousUnregister(Player player, String password, - boolean force, AuthMe plugin) { + public AsynchronousUnregister(Player player, String password, boolean force, AuthMe plugin) { + this.m = plugin.getMessages(); this.player = player; + this.name = player.getName().toLowerCase(); this.password = password; this.force = force; - name = player.getName().toLowerCase(); this.plugin = plugin; this.playerCache = new JsonCache(); } diff --git a/src/main/java/fr/xephi/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java index 99f306567..3093bf0b5 100644 --- a/src/main/java/fr/xephi/authme/settings/Messages.java +++ b/src/main/java/fr/xephi/authme/settings/Messages.java @@ -8,6 +8,7 @@ import java.io.File; /** */ // TODO ljacqu 20151124: This class is a weird mix between singleton and POJO +// TODO: change it into POJO public class Messages extends CustomConfiguration { /** The section symbol, used in Minecraft for formatting codes. */ diff --git a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java index a3bebaf55..db168cc60 100644 --- a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java +++ b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java @@ -42,7 +42,7 @@ public class ChangePasswordTask implements Runnable { */ @Override public void run() { - Messages m = Messages.getInstance(); + Messages m = plugin.getMessages(); try { String name = player.getName().toLowerCase(); String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, newPassword, name); diff --git a/src/main/java/fr/xephi/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java index 50b9f3540..31571a65b 100644 --- a/src/main/java/fr/xephi/authme/task/TimeoutTask.java +++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java @@ -12,7 +12,7 @@ public class TimeoutTask implements Runnable { private final AuthMe plugin; private final String name; - private final Messages m = Messages.getInstance(); + private final Messages m; private final Player player; /** @@ -23,6 +23,7 @@ public class TimeoutTask implements Runnable { * @param player Player */ public TimeoutTask(AuthMe plugin, String name, Player player) { + this.m = plugin.getMessages(); this.plugin = plugin; this.name = name; this.player = player; @@ -44,15 +45,16 @@ public class TimeoutTask implements Runnable { */ @Override public void run() { - if (PlayerCache.getInstance().isAuthenticated(name)) + if (PlayerCache.getInstance().isAuthenticated(name)) { return; + } Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override public void run() { - if (player.isOnline()) + if (player.isOnline()) { player.kickPlayer(m.send("timeout")[0]); + } } }); }