mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-24 17:47:38 +01:00
Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into command-perms-refactor
This commit is contained in:
commit
c288d3285e
@ -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;
|
||||
|
@ -17,6 +17,10 @@ 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.ConsoleFilter;
|
||||
import fr.xephi.authme.output.Log4JFilter;
|
||||
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;
|
||||
@ -229,7 +233,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();
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme;
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import java.util.logging.Filter;
|
||||
import java.util.logging.LogRecord;
|
||||
@ -7,20 +7,9 @@ import java.util.logging.LogRecord;
|
||||
* Console filter Class
|
||||
*
|
||||
* @author Xephi59
|
||||
* @version $Revision: 1.0 $
|
||||
*/
|
||||
public class ConsoleFilter implements Filter {
|
||||
|
||||
public ConsoleFilter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method isLoggable.
|
||||
*
|
||||
* @param record LogRecord
|
||||
*
|
||||
* @return boolean * @see java.util.logging.Filter#isLoggable(LogRecord)
|
||||
*/
|
||||
@Override
|
||||
public boolean isLoggable(LogRecord record) {
|
||||
try {
|
@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme;
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.apache.logging.log4j.Level;
|
@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme.settings;
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
/**
|
||||
* Keys for translatable messages managed by {@link Messages}.
|
82
src/main/java/fr/xephi/authme/output/Messages.java
Normal file
82
src/main/java/fr/xephi/authme/output/Messages.java
Normal file
@ -0,0 +1,82 @@
|
||||
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.
|
||||
* This class detects when the language settings have changed and will
|
||||
* automatically update to use a new language file.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance of Messages.
|
||||
*
|
||||
* @return The Messages instance
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the messages manager.
|
||||
*/
|
||||
public void reloadManager() {
|
||||
manager = new MessagesManager(Settings.messageFile);
|
||||
}
|
||||
|
||||
}
|
62
src/main/java/fr/xephi/authme/output/MessagesManager.java
Normal file
62
src/main/java/fr/xephi/authme/output/MessagesManager.java
Normal file
@ -0,0 +1,62 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.settings.CustomConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Class responsible for reading messages from a file and formatting them for Minecraft.
|
||||
* <p />
|
||||
* This class is used within {@link Messages}, which offers a high-level interface for accessing
|
||||
* or sending messages from a properties file.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme;
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
@ -1,4 +1,4 @@
|
||||
package fr.xephi.authme.settings;
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.junit.Test;
|
@ -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
|
@ -20,7 +20,8 @@ public class PlayerPermissionTest {
|
||||
// when/then
|
||||
for (PlayerPermission permission : PlayerPermission.values()) {
|
||||
if (!permission.getNode().startsWith(requiredPrefix)) {
|
||||
fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix + "'");
|
||||
fail("The permission '" + permission + "' does not start with the required prefix '" + requiredPrefix
|
||||
+ "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user