diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java index afe7e2b68..2ca1a8a0e 100644 --- a/src/main/java/fr/xephi/authme/AntiBot.java +++ b/src/main/java/fr/xephi/authme/AntiBot.java @@ -1,8 +1,8 @@ package fr.xephi.authme; import fr.xephi.authme.permission.PlayerPermission; -import fr.xephi.authme.settings.MessageKey; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.Wrapper; import org.bukkit.Bukkit; diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 4b07701f7..3018fd0fa 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -17,6 +17,8 @@ import fr.xephi.authme.hooks.BungeeCordMessage; import fr.xephi.authme.hooks.EssSpawn; import fr.xephi.authme.listener.*; import fr.xephi.authme.modules.ModuleManager; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.process.Management; @@ -227,7 +229,7 @@ public class AuthMe extends JavaPlugin { this.otherAccounts = OtherAccounts.getInstance(); // Setup messages - this.messages = new Messages(Settings.messageFile, Settings.messagesLanguage); + this.messages = Messages.getInstance(); // Set up Metrics setupMetrics(); 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 b5f07d1af..ba34491a6 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,8 +5,8 @@ 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 fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; 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 83ea810f5..1753a8307 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,8 +7,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; 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 94db21cec..cc0ac9b86 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,8 +4,8 @@ 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 fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import org.bukkit.command.CommandSender; /** 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 3f3835f35..ecae052b9 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,8 +4,8 @@ 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 fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import org.bukkit.command.CommandSender; import java.util.Date; 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 dc4172638..e9e3c9ad3 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,8 +5,8 @@ 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 fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; 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 8ddbfefdf..38e73d017 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,8 +6,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; 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 e94b5b72f..1eaf3717e 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,8 +6,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.Profiler; import org.bukkit.command.CommandSender; @@ -41,7 +41,7 @@ public class ReloadCommand extends ExecutableCommand { try { Settings.reload(); - plugin.setMessages(new Messages(Settings.messageFile, Settings.messagesLanguage)); + Messages.getInstance().reloadManager(); plugin.getModuleManager().reloadModules(); plugin.setupDatabase(); } catch (Exception e) { 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 35816fbf5..278bf13c4 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,8 +5,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.command.CommandSender; 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 f10116205..e5a8396fd 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 @@ -6,8 +6,8 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; 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 a5a194c62..4fa2bbef9 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 @@ -5,8 +5,8 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.security.RandomString; -import fr.xephi.authme.settings.MessageKey; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; 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 45d05ee32..c88ceaa87 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,8 +4,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.ChangePasswordTask; import fr.xephi.authme.util.Wrapper; 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 a2da7b376..883149973 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,8 +4,8 @@ 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 fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; 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 ab50cdb10..2af4f65a7 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,8 +8,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.Wrapper; import org.bukkit.command.CommandSender; 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 a36443b7b..070d795b2 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,8 +5,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.Wrapper; import org.bukkit.command.CommandSender; 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 96c8b3cfc..22ef35661 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,8 +4,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/converter/SqlToFlat.java b/src/main/java/fr/xephi/authme/converter/SqlToFlat.java index ee1375084..1af5594cf 100644 --- a/src/main/java/fr/xephi/authme/converter/SqlToFlat.java +++ b/src/main/java/fr/xephi/authme/converter/SqlToFlat.java @@ -5,7 +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.output.MessageKey; import org.bukkit.command.CommandSender; import java.util.List; diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 095484e5d..773ed8d5d 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -11,8 +11,8 @@ import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerPermission; -import fr.xephi.authme.settings.MessageKey; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.Utils; @@ -32,6 +32,8 @@ import org.bukkit.event.player.*; import java.util.concurrent.ConcurrentHashMap; +import static fr.xephi.authme.output.MessageKey.USERNAME_ALREADY_ONLINE_ERROR; + /** */ public class AuthMePlayerListener implements Listener { @@ -207,7 +209,7 @@ public class AuthMePlayerListener implements Listener { // Check if forceSingleSession is set to true, so kick player that has // joined with same nick of online player if (Settings.isForceSingleSessionEnabled && player.isOnline()) { - event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, m.getString("same_nick")); + event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, m.retrieveSingle(USERNAME_ALREADY_ONLINE_ERROR)); if (LimboCache.getInstance().hasLimboPlayer(name)) Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { @@ -340,7 +342,8 @@ public class AuthMePlayerListener implements Listener { return; } - if ((!Settings.isForceSingleSessionEnabled) && (event.getReason().contains(m.getString("same_nick")))) { + if (!Settings.isForceSingleSessionEnabled && event.getReason().contains( + m.retrieveSingle(USERNAME_ALREADY_ONLINE_ERROR))) { event.setCancelled(true); return; } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java index 3b5a3c803..9a1cbde48 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java @@ -2,8 +2,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.GeoLiteAPI; import org.bukkit.event.EventHandler; diff --git a/src/main/java/fr/xephi/authme/settings/MessageKey.java b/src/main/java/fr/xephi/authme/output/MessageKey.java similarity index 98% rename from src/main/java/fr/xephi/authme/settings/MessageKey.java rename to src/main/java/fr/xephi/authme/output/MessageKey.java index 72e71b631..bc024abf7 100644 --- a/src/main/java/fr/xephi/authme/settings/MessageKey.java +++ b/src/main/java/fr/xephi/authme/output/MessageKey.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.settings; +package fr.xephi.authme.output; /** * Keys for translatable messages managed by {@link Messages}. diff --git a/src/main/java/fr/xephi/authme/output/Messages.java b/src/main/java/fr/xephi/authme/output/Messages.java new file mode 100644 index 000000000..44930ba48 --- /dev/null +++ b/src/main/java/fr/xephi/authme/output/Messages.java @@ -0,0 +1,72 @@ +package fr.xephi.authme.output; + +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.util.StringUtils; +import org.bukkit.command.CommandSender; + +/** + * Class for retrieving and sending translatable messages to players. + */ +public class Messages { + + private static Messages singleton; + private final String language; + private MessagesManager manager; + + + private Messages(String language, MessagesManager manager) { + this.language = language; + this.manager = manager; + } + + public static Messages getInstance() { + if (singleton == null) { + MessagesManager manager = new MessagesManager(Settings.messageFile); + singleton = new Messages(Settings.messagesLanguage, manager); + } + return singleton; + } + + /** + * Send the given message code to the player. + * + * @param sender The entity to send the message to + * @param key The key of the message to send + */ + public void send(CommandSender sender, MessageKey key) { + String[] lines = manager.retrieve(key.getKey()); + for (String line : lines) { + sender.sendMessage(line); + } + } + + /** + * Retrieve the message from the text file and return it split by new line as an array. + * + * @param key The message key to retrieve + * + * @return The message split by new lines + */ + public String[] retrieve(MessageKey key) { + if (!Settings.messagesLanguage.equalsIgnoreCase(language)) { + reloadManager(); + } + return manager.retrieve(key.getKey()); + } + + /** + * Retrieve the message from the text file. + * + * @param key The message key to retrieve + * + * @return The message from the file + */ + public String retrieveSingle(MessageKey key) { + return StringUtils.join("\n", retrieve(key)); + } + + public void reloadManager() { + manager = new MessagesManager(Settings.messageFile); + } + +} diff --git a/src/main/java/fr/xephi/authme/output/MessagesManager.java b/src/main/java/fr/xephi/authme/output/MessagesManager.java new file mode 100644 index 000000000..0a973b908 --- /dev/null +++ b/src/main/java/fr/xephi/authme/output/MessagesManager.java @@ -0,0 +1,59 @@ +package fr.xephi.authme.output; + +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.settings.CustomConfiguration; + +import java.io.File; + +/** + * Class for retrieving and sending translatable messages to players. + */ +class MessagesManager extends CustomConfiguration { + + /** The section symbol, used in Minecraft for formatting codes. */ + private static final String SECTION_SIGN = "\u00a7"; + + + /** + * Constructor for Messages. + * + * @param file the configuration file + */ + MessagesManager(File file) { + super(file); + load(); + } + + /** + * Retrieve the message from the configuration file. + * + * @param key The key to retrieve + * + * @return The message + */ + String[] retrieve(String key) { + String message = (String) get(key); + if (message != null) { + return formatMessage(message); + } + + // Message is null: log key not being found and send error back as message + String retrievalError = "Error getting message with key '" + key + "'. "; + ConsoleLogger.showError(retrievalError + "Please verify your config file at '" + + getConfigFile().getName() + "'"); + return new String[]{ + retrievalError + "Please contact the admin to verify or update the AuthMe messages file."}; + } + + static String[] formatMessage(String message) { + // TODO: Check that the codes actually exist, i.e. replace &c but not &y + // TODO: Allow '&' to be retained with the code '&&' + String[] lines = message.split("&n"); + for (int i = 0; i < lines.length; ++i) { + // We don't initialize a StringBuilder here because mostly we will only have one entry + lines[i] = lines[i].replace("&", SECTION_SIGN); + } + return lines; + } + +} 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 b6cb623dc..5cc1f9ec8 100644 --- a/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java +++ b/src/main/java/fr/xephi/authme/process/email/AsyncChangeEmail.java @@ -5,8 +5,8 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.permission.PlayerPermission; -import fr.xephi.authme.settings.MessageKey; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.entity.Player; 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 cee3a687c..3160ddcc4 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -11,8 +11,8 @@ import fr.xephi.authme.events.ProtectInventoryEvent; import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.permission.PlayerPermission; -import fr.xephi.authme.settings.MessageKey; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.task.MessageTask; 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 1333fd98d..b3caf159a 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -11,8 +11,8 @@ import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.permission.PlayerPermission; 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.util.Utils; 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 6714c4dd1..3e719060a 100644 --- a/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/AsynchronousLogout.java @@ -5,8 +5,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.util.Utils; import fr.xephi.authme.util.Utils.GroupType; import org.bukkit.entity.Player; 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 811dbcb0c..6b4b9c0ed 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java @@ -4,8 +4,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; 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 6aaac37fe..f5f8a13c5 100644 --- a/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/AsyncRegister.java @@ -7,8 +7,8 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.permission.PlayerPermission; import fr.xephi.authme.security.PasswordSecurity; -import fr.xephi.authme.settings.MessageKey; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.entity.Player; 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 33636af48..dc95e33de 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncEmailRegister.java @@ -4,8 +4,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; 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 28faa5bf3..def20eeef 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -6,8 +6,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; 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 2268f4235..da5d19f9f 100644 --- a/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java +++ b/src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java @@ -7,8 +7,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask; diff --git a/src/main/java/fr/xephi/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java deleted file mode 100644 index 55ce0b584..000000000 --- a/src/main/java/fr/xephi/authme/settings/Messages.java +++ /dev/null @@ -1,115 +0,0 @@ -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; - -/** - * Class for retrieving and sending translatable messages to players. - */ -// 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. */ - private static final String SECTION_SIGN = "\u00a7"; - private static Messages singleton; - private String language; - - - /** - * Constructor for Messages. - * - * @param file the configuration file - * @param lang the code of the language to use - */ - public Messages(File file, String lang) { - super(file); - load(); - this.language = lang; - } - - public static Messages getInstance() { - if (singleton == null) { - singleton = new Messages(Settings.messageFile, Settings.messagesLanguage); - } - return singleton; - } - - /** - * Send the given message code to the player. - * - * @param sender The entity to send the message to - * @param key The key of the message to send - */ - public void send(CommandSender sender, MessageKey key) { - String[] lines = retrieve(key); - for (String line : lines) { - sender.sendMessage(line); - } - } - - /** - * Retrieve the message from the text file and return it split by new line as an array. - * - * @param key The message key to retrieve - * - * @return The message split by new lines - */ - public String[] retrieve(MessageKey key) { - return retrieve(key.getKey()); - } - - /** - * Retrieve the message from the text file. - * - * @param key The message key to retrieve - * - * @return The message from the file - */ - public String retrieveSingle(MessageKey key) { - return StringUtils.join("\n", retrieve(key.getKey())); - } - - /** - * Retrieve the message from the configuration file. - * - * @param key The key to retrieve - * - * @return The message - */ - private String[] retrieve(String key) { - if (!Settings.messagesLanguage.equalsIgnoreCase(language)) { - reloadMessages(); - } - String message = (String) get(key); - if (message != null) { - return formatMessage(message); - } - - // Message is null: log key not being found and send error back as message - String retrievalError = "Error getting message with key '" + key + "'. "; - ConsoleLogger.showError(retrievalError + "Please verify your config file at '" - + getConfigFile().getName() + "'"); - return new String[]{ - retrievalError + "Please contact the admin to verify or update the AuthMe messages file."}; - } - - private static String[] formatMessage(String message) { - // TODO: Check that the codes actually exist, i.e. replace &c but not &y - // TODO: Allow '&' to be retained with the code '&&' - String[] lines = message.split("&n"); - for (int i = 0; i < lines.length; ++i) { - // We don't initialize a StringBuilder here because mostly we will only have one entry - lines[i] = lines[i].replace("&", SECTION_SIGN); - } - return lines; - } - - public void reloadMessages() { - singleton = new Messages(Settings.messageFile, Settings.messagesLanguage); - } - -} diff --git a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java index 05d93dfb5..9b4dfac51 100644 --- a/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java +++ b/src/main/java/fr/xephi/authme/task/ChangePasswordTask.java @@ -5,8 +5,8 @@ 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java index dc5d06ddf..eedf08755 100644 --- a/src/main/java/fr/xephi/authme/task/TimeoutTask.java +++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java @@ -2,8 +2,8 @@ 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 fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/util/Wrapper.java b/src/main/java/fr/xephi/authme/util/Wrapper.java index 0666630b9..77f65cff5 100644 --- a/src/main/java/fr/xephi/authme/util/Wrapper.java +++ b/src/main/java/fr/xephi/authme/util/Wrapper.java @@ -2,7 +2,7 @@ package fr.xephi.authme.util; import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.Messages; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.scheduler.BukkitScheduler; diff --git a/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java index 7d33a60ef..87f113cc5 100644 --- a/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommandTest.java @@ -4,8 +4,8 @@ import fr.xephi.authme.AuthMe; import fr.xephi.authme.ReflectionTestUtils; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.command.CommandParts; -import fr.xephi.authme.settings.MessageKey; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.task.ChangePasswordTask; import fr.xephi.authme.util.WrapperMock; 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 bc6229c10..02bb65a73 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 @@ -2,8 +2,8 @@ package fr.xephi.authme.command.executable.register; 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.output.MessageKey; +import fr.xephi.authme.output.Messages; import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.WrapperMock; import org.bukkit.command.BlockCommandSender; diff --git a/src/test/java/fr/xephi/authme/settings/MessageKeyTest.java b/src/test/java/fr/xephi/authme/output/MessageKeyTest.java similarity index 96% rename from src/test/java/fr/xephi/authme/settings/MessageKeyTest.java rename to src/test/java/fr/xephi/authme/output/MessageKeyTest.java index 2eab88aa8..101306bf9 100644 --- a/src/test/java/fr/xephi/authme/settings/MessageKeyTest.java +++ b/src/test/java/fr/xephi/authme/output/MessageKeyTest.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.settings; +package fr.xephi.authme.output; import fr.xephi.authme.util.StringUtils; import org.junit.Test; diff --git a/src/test/java/fr/xephi/authme/settings/MessagesTest.java b/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java similarity index 93% rename from src/test/java/fr/xephi/authme/settings/MessagesTest.java rename to src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java index b721987ec..aa7367e2b 100644 --- a/src/test/java/fr/xephi/authme/settings/MessagesTest.java +++ b/src/test/java/fr/xephi/authme/output/MessagesIntegrationTest.java @@ -1,5 +1,6 @@ -package fr.xephi.authme.settings; +package fr.xephi.authme.output; +import fr.xephi.authme.settings.Settings; import fr.xephi.authme.util.WrapperMock; import org.bukkit.entity.Player; import org.junit.Before; @@ -18,7 +19,7 @@ import static org.mockito.Mockito.verify; /** * Test for {@link Messages}. */ -public class MessagesTest { +public class MessagesIntegrationTest { private static final String YML_TEST_FILE = "messages_test.yml"; private Messages messages; @@ -38,8 +39,9 @@ public class MessagesTest { throw new RuntimeException("File '" + YML_TEST_FILE + "' could not be loaded"); } - File file = new File(url.getFile()); - messages = new Messages(file, "en"); + Settings.messageFile = new File(url.getFile()); + Settings.messagesLanguage = "en"; + messages = Messages.getInstance(); } @Test diff --git a/src/test/java/fr/xephi/authme/util/WrapperMock.java b/src/test/java/fr/xephi/authme/util/WrapperMock.java index f622c00bd..83ed23cd2 100644 --- a/src/test/java/fr/xephi/authme/util/WrapperMock.java +++ b/src/test/java/fr/xephi/authme/util/WrapperMock.java @@ -2,7 +2,7 @@ package fr.xephi.authme.util; import fr.xephi.authme.AuthMe; import fr.xephi.authme.cache.auth.PlayerCache; -import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.output.Messages; import org.bukkit.Server; import org.bukkit.scheduler.BukkitScheduler; import org.mockito.Mockito;