diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 1ad433a2a..c1750c56b 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -20,10 +20,7 @@ import fr.xephi.authme.listener.*; import fr.xephi.authme.modules.ModuleManager; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.process.Management; -import fr.xephi.authme.settings.Messages; -import fr.xephi.authme.settings.OtherAccounts; -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.settings.Spawn; +import fr.xephi.authme.settings.*; import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.StringUtils; import fr.xephi.authme.util.Utils; @@ -837,7 +834,7 @@ public class AuthMe extends JavaPlugin { if (PlayerCache.getInstance().isAuthenticated(name)) { String email = database.getAuth(name).getEmail(); if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) - messages.send(player, "add_email"); + messages.send(player, MessageKey.ADD_EMAIL_MESSAGE); } } } 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 6d8693e81..b5f07d1af 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 @@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -40,16 +41,16 @@ public class AccountsCommand extends ExecutableCommand { try { auth = plugin.database.getAuth(playerQueryFinal.toLowerCase()); } catch (NullPointerException npe) { - m.send(sender, "unknown_user"); + m.send(sender, MessageKey.UNKNOWN_USER); return; } if (auth == null) { - m.send(sender, "unknown_user"); + m.send(sender, MessageKey.UNKNOWN_USER); return; } List accountList = plugin.database.getAllAuthsByName(auth); if (accountList == null || accountList.isEmpty()) { - m.send(sender, "user_unknown"); + m.send(sender, MessageKey.USER_NOT_REGISTERED); return; } if (accountList.size() == 1) { @@ -81,7 +82,7 @@ public class AccountsCommand extends ExecutableCommand { } catch (Exception e) { ConsoleLogger.showError(e.getMessage()); ConsoleLogger.writeStackTrace(e); - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); return; } 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 fe96900aa..83ea810f5 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 @@ -7,6 +7,7 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.Bukkit; @@ -31,20 +32,20 @@ public class ChangePasswordCommand extends ExecutableCommand { // Validate the password 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)) { - m.send(sender, "password_error"); + m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR); return true; } if (playerPassLowerCase.equalsIgnoreCase(playerName)) { - m.send(sender, "password_error_nick"); + m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR); return true; } if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) { - m.send(sender, "pass_len"); + m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH); return true; } if (!Settings.unsafePasswords.isEmpty()) { if (Settings.unsafePasswords.contains(playerPassLowerCase)) { - m.send(sender, "password_error_unsafe"); + m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR); return true; } } @@ -58,7 +59,7 @@ public class ChangePasswordCommand extends ExecutableCommand { try { hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPass, playerNameLowerCase); } catch (NoSuchAlgorithmException e) { - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); return; } PlayerAuth auth = null; @@ -68,7 +69,7 @@ public class ChangePasswordCommand extends ExecutableCommand { auth = plugin.database.getAuth(playerNameLowerCase); } if (auth == null) { - m.send(sender, "unknown_user"); + m.send(sender, MessageKey.UNKNOWN_USER); return; } auth.setHash(hash); @@ -77,7 +78,7 @@ public class ChangePasswordCommand extends ExecutableCommand { plugin.database.updateSalt(auth); } if (!plugin.database.updatePassword(auth)) { - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); return; } sender.sendMessage("pwd_changed"); 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 5cfb4f033..94db21cec 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 @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.command.CommandSender; @@ -32,7 +33,7 @@ public class GetEmailCommand extends ExecutableCommand { Messages m = plugin.getMessages(); PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase()); if (auth == null) { - m.send(sender, "unknown_user"); + m.send(sender, MessageKey.UNKNOWN_USER); return true; } 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 84fd210b9..3f3835f35 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 @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.command.CommandSender; @@ -28,11 +29,11 @@ public class LastLoginCommand extends ExecutableCommand { try { auth = plugin.database.getAuth(playerName.toLowerCase()); } catch (NullPointerException e) { - m.send(sender, "unknown_user"); + m.send(sender, MessageKey.UNKNOWN_USER); return true; } if (auth == null) { - m.send(sender, "user_unknown"); + m.send(sender, MessageKey.USER_NOT_REGISTERED); return true; } 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 24d4d93dd..dc4172638 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 @@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -41,7 +42,7 @@ public class PurgeLastPositionCommand extends ExecutableCommand { // Get the user auth and make sure the user exists PlayerAuth auth = plugin.database.getAuth(playerNameLowerCase); if (auth == null) { - m.send(sender, "unknown_user"); + m.send(sender, MessageKey.UNKNOWN_USER); return true; } 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 afc265fcc..70595cdb9 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 @@ -6,6 +6,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.Bukkit; @@ -42,20 +43,20 @@ public class RegisterCommand extends ExecutableCommand { // Command logic 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(sender, "password_error"); + m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR); return true; } if (playerPassLowerCase.equalsIgnoreCase(playerName)) { - m.send(sender, "password_error_nick"); + m.send(sender, MessageKey.PASSWORD_IS_USERNAME_ERROR); return true; } if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) { - m.send(sender, "pass_len"); + m.send(sender, MessageKey.INVALID_PASSWORD_LENGTH); return true; } if (!Settings.unsafePasswords.isEmpty()) { if (Settings.unsafePasswords.contains(playerPassLowerCase)) { - m.send(sender, "password_error_unsafe"); + m.send(sender, MessageKey.PASSWORD_UNSAFE_ERROR); return true; } } @@ -65,7 +66,7 @@ public class RegisterCommand extends ExecutableCommand { public void run() { try { if (plugin.database.isAuthAvailable(playerNameLowerCase)) { - m.send(sender, "user_regged"); + m.send(sender, MessageKey.NAME_ALREADY_REGISTERED); return; } String hash = PasswordSecurity.getHash(Settings.getPasswordHash, playerPassLowerCase, playerNameLowerCase); @@ -74,17 +75,17 @@ public class RegisterCommand extends ExecutableCommand { auth.setSalt(PasswordSecurity.userSalt.get(playerNameLowerCase)); else auth.setSalt(""); if (!plugin.database.saveAuth(auth)) { - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); return; } plugin.database.setUnlogged(playerNameLowerCase); if (Bukkit.getPlayerExact(playerName) != null) Bukkit.getPlayerExact(playerName).kickPlayer("An admin just registered you, please log again"); - m.send(sender, "registered"); + m.send(sender, MessageKey.REGISTER_SUCCESS); ConsoleLogger.info(playerNameLowerCase + " registered"); } catch (NoSuchAlgorithmException ex) { ConsoleLogger.showError(ex.getMessage()); - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); } } 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 56cb6680c..e94b5b72f 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 @@ -6,6 +6,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.Profiler; @@ -52,7 +53,7 @@ public class ReloadCommand extends ExecutableCommand { // Show a status message // TODO: add the profiler result - m.send(sender, "reload"); + m.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); // AuthMeReloaded reloaded, show a status message // sender.sendMessage(ChatColor.GREEN + "AuthMeReloaded has been reloaded successfully, took " + p.getTimeFormatted() + "!"); 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 11c5d75a9..35816fbf5 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 @@ -5,6 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.command.CommandSender; @@ -36,21 +37,21 @@ public class SetEmailCommand extends ExecutableCommand { // Validate the email address if (!Settings.isEmailCorrect(playerEmail)) { - m.send(sender, "email_invalid"); + m.send(sender, MessageKey.INVALID_EMAIL); return true; } // Validate the user PlayerAuth auth = plugin.database.getAuth(playerName.toLowerCase()); if (auth == null) { - m.send(sender, "unknown_user"); + m.send(sender, MessageKey.UNKNOWN_USER); return true; } // Set the email address auth.setEmail(playerEmail); if (!plugin.database.updateEmail(auth)) { - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); return true; } @@ -59,7 +60,7 @@ public class SetEmailCommand extends ExecutableCommand { PlayerCache.getInstance().updatePlayer(auth); // Show a status message - m.send(sender, "email_changed"); + m.send(sender, MessageKey.EMAIL_CHANGED_SUCCESS); return true; } } 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 509bb3007..42083612f 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 @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.ChangePasswordTask; @@ -32,7 +33,7 @@ public class ChangePasswordCommand extends ExecutableCommand { Player player = (Player) sender; String name = player.getName().toLowerCase(); if (!PlayerCache.getInstance().isAuthenticated(name)) { - m.send(player, "not_logged_in"); + m.send(player, MessageKey.NOT_LOGGED_IN); return true; } @@ -43,21 +44,21 @@ public class ChangePasswordCommand extends ExecutableCommand { || playerPassLowerCase.contains("from") || playerPassLowerCase.contains("select") || playerPassLowerCase.contains(";") || playerPassLowerCase.contains("null") || !playerPassLowerCase.matches(Settings.getPassRegex)) { - m.send(player, "password_error"); + m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR); return true; } if (playerPassLowerCase.equalsIgnoreCase(name)) { - m.send(player, "password_error_nick"); + m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR); return true; } if (playerPassLowerCase.length() < Settings.getPasswordMinLen || playerPassLowerCase.length() > Settings.passwordMaxLength) { - m.send(player, "pass_len"); + m.send(player, MessageKey.INVALID_PASSWORD_LENGTH); return true; } if (!Settings.unsafePasswords.isEmpty()) { if (Settings.unsafePasswords.contains(playerPassLowerCase)) { - m.send(player, "password_error_unsafe"); + m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR); 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 3604f8421..a2da7b376 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 @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.converter.*; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -35,7 +36,7 @@ public class ConverterCommand extends ExecutableCommand { // Determine the job type ConvertType jobType = ConvertType.fromName(job); if (jobType == null) { - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); return true; } 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 67f75c61d..ce4dedf47 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 @@ -8,6 +8,7 @@ import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.command.CommandSender; @@ -38,12 +39,12 @@ public class RecoverEmailCommand extends ExecutableCommand { final Messages m = plugin.getMessages(); if (plugin.mail == null) { - m.send(player, "error"); + m.send(player, MessageKey.ERROR); return true; } if (plugin.database.isAuthAvailable(playerName)) { if (PlayerCache.getInstance().isAuthenticated(playerName)) { - m.send(player, "logged_in"); + m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); return true; } try { @@ -56,29 +57,29 @@ public class RecoverEmailCommand extends ExecutableCommand { } else if (plugin.database.isAuthAvailable(playerName)) { auth = plugin.database.getAuth(playerName); } else { - m.send(player, "unknown_user"); + m.send(player, MessageKey.UNKNOWN_USER); return true; } if (Settings.getmailAccount.equals("") || Settings.getmailAccount.isEmpty()) { - m.send(player, "error"); + m.send(player, MessageKey.ERROR); return true; } if (!playerMail.equalsIgnoreCase(auth.getEmail()) || playerMail.equalsIgnoreCase("your@email.com") || auth.getEmail().equalsIgnoreCase("your@email.com")) { - m.send(player, "email_invalid"); + m.send(player, MessageKey.INVALID_EMAIL); return true; } auth.setHash(hashNew); plugin.database.updatePassword(auth); plugin.mail.main(auth, thePass); - m.send(player, "email_send"); + m.send(player, MessageKey.RECOVERY_EMAIL_SENT_MESSAGE); } catch (NoSuchAlgorithmException | NoClassDefFoundError ex) { ex.printStackTrace(); ConsoleLogger.showError(ex.getMessage()); - m.send(sender, "error"); + m.send(sender, MessageKey.ERROR); } } else { - m.send(player, "reg_email_msg"); + m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); } return true; 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 3fb45a51d..404c2d7b8 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 @@ -5,6 +5,7 @@ import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.command.CommandSender; @@ -29,7 +30,7 @@ public class RegisterCommand extends ExecutableCommand { // Make sure the command arguments are valid final Player player = (Player) sender; if (commandArguments.getCount() == 0 || (Settings.getEnablePasswordVerifier && commandArguments.getCount() < 2)) { - m.send(player, "usage_reg"); + m.send(player, MessageKey.USAGE_REGISTER); return true; } @@ -37,13 +38,13 @@ public class RegisterCommand extends ExecutableCommand { if (Settings.emailRegistration && !Settings.getmailAccount.isEmpty()) { if (Settings.doubleEmailCheck) { if (commandArguments.getCount() < 2 || !commandArguments.get(0).equals(commandArguments.get(1))) { - m.send(player, "usage_reg"); + m.send(player, MessageKey.USAGE_REGISTER); return true; } } final String email = commandArguments.get(0); if (!Settings.isEmailCorrect(email)) { - m.send(player, "email_invalid"); + m.send(player, MessageKey.INVALID_EMAIL); return true; } final String thePass = new RandomString(Settings.getRecoveryPassLength).nextString(); @@ -52,7 +53,7 @@ public class RegisterCommand extends ExecutableCommand { } if (commandArguments.getCount() > 1 && Settings.getEnablePasswordVerifier) { if (!commandArguments.get(0).equals(commandArguments.get(1))) { - m.send(player, "password_error"); + m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR); 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 ece343c85..96c8b3cfc 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 @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -43,7 +44,7 @@ public class UnregisterCommand extends ExecutableCommand { // Make sure the player is authenticated if (!PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) { - m.send(player, "not_logged_in"); + m.send(player, MessageKey.NOT_LOGGED_IN); return true; } diff --git a/src/main/java/fr/xephi/authme/converter/SqlToFlat.java b/src/main/java/fr/xephi/authme/converter/SqlToFlat.java index 836486b89..e723ae2a3 100644 --- a/src/main/java/fr/xephi/authme/converter/SqlToFlat.java +++ b/src/main/java/fr/xephi/authme/converter/SqlToFlat.java @@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.FlatFile; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.command.CommandSender; @@ -52,7 +53,7 @@ public class SqlToFlat implements Converter { sender.sendMessage("Successfully convert from SQL table to file auths.db"); } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); - plugin.getMessages().send(sender, "error"); + plugin.getMessages().send(sender, MessageKey.ERROR); } } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index aa9b16422..43044ac8a 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -2,7 +2,6 @@ package fr.xephi.authme.listener; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; - import fr.xephi.authme.AntiBot; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; @@ -11,6 +10,7 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.permission.PermissionsManager; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.GeoLiteAPI; @@ -29,7 +29,6 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.*; -import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; /** @@ -75,12 +74,12 @@ public class AuthMePlayerListener implements Listener { event.setCancelled(true); if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) { - m.send(player, "login_msg"); + m.send(player, MessageKey.LOGIN_MESSAGE); } else { if (Settings.emailRegistration) { - m.send(player, "reg_email_msg"); + m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); } else { - m.send(player, "reg_msg"); + m.send(player, MessageKey.REGISTER_MESSAGE); } } @@ -190,7 +189,7 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isMovementAllowed) { event.setTo(event.getFrom()); - if(Settings.isRemoveSpeedEnabled) { + if (Settings.isRemoveSpeedEnabled) { player.setFlySpeed(0.0f); player.setWalkSpeed(0.0f); } @@ -297,11 +296,11 @@ public class AuthMePlayerListener implements Listener { } else { Player pl = plugin.generateKickPlayer(Utils.getOnlinePlayers()); if (pl != null) { - pl.kickPlayer(m.send("kick_forvip")[0]); + pl.kickPlayer(m.retrieveSingle(MessageKey.KICK_FOR_VIP)); event.allow(); } else { ConsoleLogger.info("The player " + event.getPlayer().getName() + " tryed to join, but the server was full"); - event.setKickMessage(m.send("kick_fullserver")[0]); + event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER)); event.setResult(PlayerLoginEvent.Result.KICK_FULL); } } @@ -316,7 +315,7 @@ public class AuthMePlayerListener implements Listener { final Player player = event.getPlayer(); if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, "authme.vip")) { - event.setKickMessage(m.send("kick_fullserver")[0]); + event.setKickMessage(m.retrieveSingle(MessageKey.KICK_FULL_SERVER)); event.setResult(PlayerLoginEvent.Result.KICK_FULL); return; } @@ -331,7 +330,7 @@ public class AuthMePlayerListener implements Listener { if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) { String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); if (Settings.countriesBlacklist.contains(code)) { - event.setKickMessage(m.send("country_banned")[0]); + event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } @@ -340,7 +339,7 @@ public class AuthMePlayerListener implements Listener { if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) { String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); if (!Settings.countries.contains(code)) { - event.setKickMessage(m.send("country_banned")[0]); + event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } @@ -353,20 +352,20 @@ public class AuthMePlayerListener implements Listener { event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } else { - event.setKickMessage(m.send("reg_only")[0]); + event.setKickMessage(m.retrieveSingle(MessageKey.MUST_REGISTER_MESSAGE)); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } } if (name.length() > Settings.getMaxNickLength || name.length() < Settings.getMinNickLength) { - event.setKickMessage(Arrays.toString(m.send("name_len"))); + event.setKickMessage(m.retrieveSingle(MessageKey.INVALID_NAME_LENGTH)); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } if (!Settings.nickPattern.matcher(player.getName()).matches() || name.equalsIgnoreCase("Player")) { - event.setKickMessage(m.send("regex")[0].replace("REG_EX", Settings.getNickRegex)); + event.setKickMessage(m.retrieveSingle(MessageKey.INVALID_NAME_CHARACTERS).replace("REG_EX", Settings.getNickRegex)); event.setResult(PlayerLoginEvent.Result.KICK_OTHER); return; } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java index 0be77e935..3b5a3c803 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java @@ -2,6 +2,7 @@ package fr.xephi.authme.listener; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.GeoLiteAPI; @@ -44,7 +45,7 @@ public class AuthMeServerListener implements Listener { String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); if (!Settings.countriesBlacklist.isEmpty()) { if (Settings.countriesBlacklist.contains(countryCode)) { - event.setMotd(m.send("country_banned")[0]); + event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); return; } } @@ -53,7 +54,7 @@ public class AuthMeServerListener implements Listener { if (Settings.countries.contains(countryCode)) { event.setMotd(plugin.getServer().getMotd()); } else { - event.setMotd(m.send("country_banned")[0]); + event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR)); } } } 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 c3836579d..d9ba9182e 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -42,8 +42,7 @@ public class AsyncChangeEmail { if (Settings.getmaxRegPerEmail > 0) { if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) { - // TODO ljacqu 20151124: max_reg is not in enum - m.send(player, "max_reg"); + m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return; } } @@ -83,15 +82,16 @@ public class AsyncChangeEmail { } m.send(player, MessageKey.EMAIL_CHANGED_SUCCESS); // TODO ljacqu 20151124: Did I really miss "email_defined" or is it not present in the 'en' messages? - player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail()); + // player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail()); } else { if (plugin.database.isAuthAvailable(playerName)) { m.send(player, MessageKey.LOGIN_MESSAGE); } else { - if (Settings.emailRegistration) + if (Settings.emailRegistration) { m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); - else + } else { m.send(player, MessageKey.REGISTER_MESSAGE); + } } } } catch (Exception e) { 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 781dc60e6..c0468dba1 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -10,6 +10,7 @@ import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; @@ -80,7 +81,7 @@ public class AsynchronousLogin { } if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { plugin.cap.put(name, rdm.nextString()); - for (String s : m.send("usage_captcha")) { + for (String s : m.retrieve(MessageKey.USAGE_CAPTCHA)) { player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("", plugin.cap.get(name))); } return true; @@ -100,18 +101,18 @@ public class AsynchronousLogin { */ protected PlayerAuth preAuth() { if (PlayerCache.getInstance().isAuthenticated(name)) { - m.send(player, "logged_in"); + m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); return null; } if (!database.isAuthAvailable(name)) { - m.send(player, "user_unknown"); + m.send(player, MessageKey.USER_NOT_REGISTERED); if (LimboCache.getInstance().hasLimboPlayer(name)) { LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId().cancel(); String[] msg; if (Settings.emailRegistration) { - msg = m.send("reg_email_msg"); + msg = m.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE); } else { - msg = m.send("reg_msg"); + msg = m.retrieve(MessageKey.REGISTER_MESSAGE); } BukkitTask msgT = Bukkit.getScheduler().runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, Settings.getWarnMessageInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); @@ -120,17 +121,17 @@ public class AsynchronousLogin { } if (Settings.getMaxLoginPerIp > 0 && !plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && !getIP().equalsIgnoreCase("127.0.0.1") && !getIP().equalsIgnoreCase("localhost")) { if (plugin.isLoggedIp(name, getIP())) { - m.send(player, "logged_in"); + m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); return null; } } PlayerAuth pAuth = database.getAuth(name); if (pAuth == null) { - m.send(player, "user_unknown"); + m.send(player, MessageKey.USER_NOT_REGISTERED); return null; } if (!Settings.getMySQLColumnGroup.isEmpty() && pAuth.getGroupId() == Settings.getNonActivatedGroup) { - m.send(player, "vb_nonActiv"); + m.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); return null; } AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player); @@ -153,7 +154,7 @@ public class AsynchronousLogin { passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, realName); } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); - m.send(player, "error"); + m.send(player, MessageKey.ERROR); return; } if (passwordVerified && player.isOnline()) { @@ -171,17 +172,19 @@ public class AsynchronousLogin { player.setNoDamageTicks(0); if (!forceLogin) - m.send(player, "login"); + m.send(player, MessageKey.LOGIN_SUCCESS); displayOtherAccounts(auth, player); if (Settings.recallEmail) { - if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) - m.send(player, "add_email"); + if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) { + m.send(player, MessageKey.EMAIL_ADDED_SUCCESS); + } } - if (!Settings.noConsoleSpam) + if (!Settings.noConsoleSpam) { ConsoleLogger.info(realName + " logged in!"); + } // makes player isLoggedin via API PlayerCache.getInstance().addPlayer(auth); @@ -211,11 +214,11 @@ public class AsynchronousLogin { if (AuthMePlayerListener.gameMode != null && AuthMePlayerListener.gameMode.containsKey(name)) { player.setGameMode(AuthMePlayerListener.gameMode.get(name)); } - player.kickPlayer(m.send("wrong_pwd")[0]); + player.kickPlayer(m.retrieveSingle(MessageKey.WRONG_PASSWORD)); } }); } else { - m.send(player, "wrong_pwd"); + m.send(player, MessageKey.WRONG_PASSWORD); } } else { ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... "); 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 79d2959ea..6714c4dd1 100644 --- a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java @@ -5,6 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils.GroupType; @@ -39,7 +40,7 @@ public class AsynchronousLogout { private void preLogout() { if (!PlayerCache.getInstance().isAuthenticated(name)) { - m.send(player, "not_logged_in"); + m.send(player, MessageKey.NOT_LOGGED_IN); canLogout = false; } } 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 76600c599..811dbcb0c 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.events.LogoutEvent; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; @@ -58,7 +59,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable { BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), timeOut); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } - BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval)); + BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), interval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); if (player.isInsideVehicle() && player.getVehicle() != null) player.getVehicle().eject(); @@ -75,7 +76,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable { } // Player is now logout... Time to fire event ! Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player)); - m.send(player, "logout"); + m.send(player, MessageKey.LOGOUT_SUCCESS); ConsoleLogger.info(player.getName() + " logged out"); } 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 f18f02c30..4487990a4 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -6,6 +6,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.entity.Player; @@ -61,29 +62,29 @@ public class AsyncRegister { protected boolean preRegisterCheck() throws Exception { String passLow = password.toLowerCase(); if (PlayerCache.getInstance().isAuthenticated(name)) { - m.send(player, "logged_in"); + m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR); return false; } else if (!Settings.isRegistrationEnabled) { - m.send(player, "reg_disabled"); + m.send(player, MessageKey.REGISTRATION_DISABLED); return false; } else if (passLow.contains("delete") || passLow.contains("where") || passLow.contains("insert") || passLow.contains("modify") || passLow.contains("from") || passLow.contains("select") || passLow.contains(";") || passLow.contains("null") || !passLow.matches(Settings.getPassRegex)) { - m.send(player, "password_error"); + m.send(player, MessageKey.PASSWORD_MATCH_ERROR); return false; } else if (passLow.equalsIgnoreCase(player.getName())) { - m.send(player, "password_error_nick"); + m.send(player, MessageKey.PASSWORD_IS_USERNAME_ERROR); return false; } else if (password.length() < Settings.getPasswordMinLen || password.length() > Settings.passwordMaxLength) { - m.send(player, "pass_len"); + m.send(player, MessageKey.INVALID_PASSWORD_LENGTH); return false; } else if (!Settings.unsafePasswords.isEmpty() && Settings.unsafePasswords.contains(password.toLowerCase())) { - m.send(player, "password_error_unsafe"); + m.send(player, MessageKey.PASSWORD_UNSAFE_ERROR); return false; } else if (database.isAuthAvailable(name)) { - m.send(player, "user_regged"); + m.send(player, MessageKey.NAME_ALREADY_REGISTERED); return false; } else if (Settings.getmaxRegPerIp > 0) { if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp && !getIp().equalsIgnoreCase("127.0.0.1") && !getIp().equalsIgnoreCase("localhost")) { - m.send(player, "max_reg"); + m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return false; } } @@ -97,7 +98,7 @@ public class AsyncRegister { if (!email.isEmpty() && !email.equals("")) { if (Settings.getmaxRegPerEmail > 0) { if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { - m.send(player, "max_reg"); + m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return; } } @@ -108,7 +109,7 @@ public class AsyncRegister { } catch (Exception e) { ConsoleLogger.showError(e.getMessage()); ConsoleLogger.writeStackTrace(e); - m.send(player, "error"); + m.send(player, MessageKey.ERROR); } } @@ -120,7 +121,7 @@ public class AsyncRegister { protected void emailRegister() throws Exception { if (Settings.getmaxRegPerEmail > 0) { if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) { - m.send(player, "max_reg"); + m.send(player, MessageKey.MAX_REGISTER_EXCEEDED); return; } } @@ -146,7 +147,7 @@ public class AsyncRegister { hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); } catch (NoSuchAlgorithmException e) { ConsoleLogger.showError(e.getMessage()); - m.send(player, "error"); + m.send(player, MessageKey.ERROR); return; } if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name)) { @@ -155,7 +156,7 @@ public class AsyncRegister { auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime(), player.getName()); } if (!database.saveAuth(auth)) { - m.send(player, "error"); + m.send(player, MessageKey.ERROR); return; } if (!Settings.forceRegLogin) { 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 0a1fa59d4..33636af48 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; @@ -46,7 +47,7 @@ public class ProcessSyncEmailRegister implements Runnable { if (!Settings.getRegisteredGroup.isEmpty()) { Utils.setGroup(player, Utils.GroupType.REGISTERED); } - m.send(player, "vb_nonActiv"); + m.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED); int time = Settings.getRegistrationTimeout * 20; int msgInterval = Settings.getWarnMessageInterval; @@ -58,7 +59,7 @@ public class ProcessSyncEmailRegister implements Runnable { } if (limbo != null) { limbo.getMessageTaskId().cancel(); - BukkitTask nwMsg = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), msgInterval)); + BukkitTask nwMsg = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), msgInterval)); limbo.setMessageTaskId(nwMsg); } 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 0b188948a..28faa5bf3 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -6,6 +6,7 @@ import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.events.LoginEvent; import fr.xephi.authme.events.RestoreInventoryEvent; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; @@ -69,7 +70,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } - BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval)); + BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), interval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); if (player.isInsideVehicle() && player.getVehicle() != null) { player.getVehicle().eject(); @@ -104,9 +105,9 @@ public class ProcessSyncronousPasswordRegister implements Runnable { if (!Settings.getRegisteredGroup.isEmpty()) { Utils.setGroup(player, Utils.GroupType.REGISTERED); } - m.send(player, "registered"); + m.send(player, MessageKey.REGISTER_SUCCESS); if (!Settings.getmailAccount.isEmpty()) - m.send(player, "add_email"); + m.send(player, MessageKey.ADD_EMAIL_MESSAGE); if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(false); player.setFlying(false); @@ -126,7 +127,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable { // Kick Player after Registration is enabled, kick the player if (Settings.forceRegKick) { - player.kickPlayer(m.send("registered")[0]); + player.kickPlayer(m.retrieveSingle(MessageKey.REGISTER_SUCCESS)); return; } 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 0f7cfaa29..2268f4235 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -5,7 +5,9 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.backup.JsonCache; import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; @@ -63,48 +65,54 @@ public class AsynchronousUnregister { try { if (force || PasswordSecurity.comparePasswordWithHash(password, PlayerCache.getInstance().getAuth(name).getHash(), player.getName())) { if (!plugin.database.removeAuth(name)) { - player.sendMessage("error"); + m.send(player, MessageKey.ERROR); return; } + int timeOut = Settings.getRegistrationTimeout * 20; if (Settings.isForcedRegistrationEnabled) { Utils.teleportToSpawn(player); player.saveData(); PlayerCache.getInstance().removePlayer(player.getName().toLowerCase()); - if (!Settings.getRegisteredGroup.isEmpty()) + if (!Settings.getRegisteredGroup.isEmpty()) { Utils.setGroup(player, GroupType.UNREGISTERED); + } LimboCache.getInstance().addLimboPlayer(player); - int delay = Settings.getRegistrationTimeout * 20; + LimboPlayer limboPlayer = LimboCache.getInstance().getLimboPlayer(name); int interval = Settings.getWarnMessageInterval; BukkitScheduler scheduler = plugin.getServer().getScheduler(); - if (delay != 0) { - BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay); - LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); + if (timeOut != 0) { + BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, + new TimeoutTask(plugin, name, player), timeOut); + limboPlayer.setTimeoutTaskId(id); } - LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("reg_msg"), interval))); - m.send(player, "unregistered"); + limboPlayer.setMessageTaskId(scheduler.runTaskAsynchronously(plugin, + new MessageTask(plugin, name, m.retrieve(MessageKey.REGISTER_MESSAGE), interval))); + m.send(player, MessageKey.UNREGISTERED_SUCCESS); ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); return; } if (!Settings.unRegisteredGroup.isEmpty()) { Utils.setGroup(player, Utils.GroupType.UNREGISTERED); } - PlayerCache.getInstance().removePlayer(player.getName().toLowerCase()); + PlayerCache.getInstance().removePlayer(name); // check if Player cache File Exist and delete it, preventing // duplication of items if (playerCache.doesCacheExist(player)) { playerCache.removeCache(player); } - if (Settings.applyBlindEffect) - player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); + // Apply blind effect + if (Settings.applyBlindEffect) { + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeOut, 2)); + } if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { player.setWalkSpeed(0.0f); player.setFlySpeed(0.0f); } - m.send(player, "unregistered"); + m.send(player, MessageKey.UNREGISTERED_SUCCESS); ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); Utils.teleportToSpawn(player); } else { - m.send(player, "wrong_pwd"); + m.send(player, MessageKey.WRONG_PASSWORD); } } catch (NoSuchAlgorithmException ignored) { } diff --git a/src/main/java/fr/xephi/authme/settings/MessageKey.java b/src/main/java/fr/xephi/authme/settings/MessageKey.java index f2316dedf..2fc1520ad 100644 --- a/src/main/java/fr/xephi/authme/settings/MessageKey.java +++ b/src/main/java/fr/xephi/authme/settings/MessageKey.java @@ -39,6 +39,10 @@ public enum MessageKey { REGISTER_EMAIL_MESSAGE("reg_email_msg"), + MAX_REGISTER_EXCEEDED("max_reg"), + + USAGE_REGISTER("usage_reg"), + USAGE_UNREGISTER("usage_unreg"), PASSWORD_CHANGED_SUCCESS("pwd_changed"), @@ -57,7 +61,7 @@ public enum MessageKey { ALREADY_LOGGED_IN_ERROR("logged_in"), - LOGOUT_SUCCESS("logout_success"), + LOGOUT_SUCCESS("logout"), USERNAME_ALREADY_ONLINE_ERROR("same_nick"), diff --git a/src/main/java/fr/xephi/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java index 3093bf0b5..e603c317d 100644 --- a/src/main/java/fr/xephi/authme/settings/Messages.java +++ b/src/main/java/fr/xephi/authme/settings/Messages.java @@ -1,6 +1,7 @@ package fr.xephi.authme.settings; import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.util.StringUtils; import org.bukkit.command.CommandSender; import java.io.File; @@ -13,7 +14,7 @@ public class Messages extends CustomConfiguration { /** The section symbol, used in Minecraft for formatting codes. */ private static final String SECTION_SIGN = "\u00a7"; - private static Messages singleton = null; + private static Messages singleton; private String language = "en"; @@ -26,7 +27,6 @@ public class Messages extends CustomConfiguration { public Messages(File file, String lang) { super(file); load(); - singleton = this; this.language = lang; } @@ -70,6 +70,10 @@ public class Messages extends CustomConfiguration { return retrieve(key.getKey()); } + public String retrieveSingle(MessageKey key) { + return StringUtils.join("\n", retrieve(key.getKey())); + } + /** * Retrieve the message from the text file and returns it split by new line as an array. * diff --git a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java index db168cc60..93d05f12f 100644 --- a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java +++ b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java @@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.entity.Player; @@ -55,19 +56,19 @@ public class ChangePasswordTask implements Runnable { auth.setSalt(""); } if (!plugin.database.updatePassword(auth)) { - m.send(player, "error"); + m.send(player, MessageKey.ERROR); return; } plugin.database.updateSalt(auth); PlayerCache.getInstance().updatePlayer(auth); - m.send(player, "pwd_changed"); + m.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS); ConsoleLogger.info(player.getName() + " changed his password"); } else { - m.send(player, "wrong_pwd"); + m.send(player, MessageKey.WRONG_PASSWORD); } } catch (NoSuchAlgorithmException ex) { ConsoleLogger.showError(ex.getMessage()); - m.send(player, "error"); + m.send(player, MessageKey.ERROR); } } } diff --git a/src/main/java/fr/xephi/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java index 31571a65b..dc5d06ddf 100644 --- a/src/main/java/fr/xephi/authme/task/TimeoutTask.java +++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java @@ -2,6 +2,7 @@ package fr.xephi.authme.task; import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -53,7 +54,7 @@ public class TimeoutTask implements Runnable { @Override public void run() { if (player.isOnline()) { - player.kickPlayer(m.send("timeout")[0]); + player.kickPlayer(m.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR)); } } }); diff --git a/src/main/java/fr/xephi/authme/util/StringUtils.java b/src/main/java/fr/xephi/authme/util/StringUtils.java index 395e4db1b..ad6e560d1 100644 --- a/src/main/java/fr/xephi/authme/util/StringUtils.java +++ b/src/main/java/fr/xephi/authme/util/StringUtils.java @@ -89,6 +89,31 @@ public class StringUtils { return sb.toString(); } + /** + * Joins a list of elements into a single string with the specified delimiter. + * + * @param delimiter the delimiter to use + * @param elements the elements to join + * + * @return a new String that is composed of the elements separated by the delimiter + */ + public static String join(CharSequence delimiter, CharSequence... elements) { + if (elements.length == 0) { + return ""; + } + if (delimiter == null) { + delimiter = ""; + } + StringBuilder sb = new StringBuilder(elements[0]); + if (elements.length > 1) { + for (int i = 1; i < elements.length; i++) { + sb.append(delimiter); + sb.append(elements[i]); + } + } + return sb.toString(); + } + /** * Get a full stack trace of an exception as a string. * @@ -107,6 +132,7 @@ public class StringUtils { // Return the result as a string return stringWriter.toString(); } + /** * Format the information from a Throwable as string, retaining the type and its message. * diff --git a/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java index 0b2ba2cd0..b408e43cd 100644 --- a/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/register/RegisterCommandTest.java @@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMeMockUtil; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.process.Management; +import fr.xephi.authme.settings.MessageKey; import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.command.BlockCommandSender; @@ -69,7 +70,7 @@ public class RegisterCommandTest { command.executeCommand(sender, new CommandParts(), new CommandParts()); // then - verify(messagesMock).send(sender, "usage_reg"); + verify(messagesMock).send(sender, MessageKey.USAGE_REGISTER); verify(managementMock, never()).performRegister(any(Player.class), anyString(), anyString()); }