Package cleanup
- authme.cache to authme.data - Rename PlayerData to LimboPlayer to match with LimboCache - Move authme.converter to authme.datasource.converter - Split output package into output and message
This commit is contained in:
@@ -1,181 +0,0 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
/**
|
||||
* Keys for translatable messages managed by {@link Messages}.
|
||||
*/
|
||||
public enum MessageKey {
|
||||
|
||||
DENIED_COMMAND("denied_command"),
|
||||
|
||||
SAME_IP_ONLINE("same_ip_online"),
|
||||
|
||||
DENIED_CHAT("denied_chat"),
|
||||
|
||||
KICK_ANTIBOT("kick_antibot"),
|
||||
|
||||
UNKNOWN_USER("unknown_user"),
|
||||
|
||||
UNSAFE_QUIT_LOCATION("unsafe_spawn"),
|
||||
|
||||
NOT_LOGGED_IN("not_logged_in"),
|
||||
|
||||
REGISTER_VOLUNTARILY("reg_voluntarily"),
|
||||
|
||||
USAGE_LOGIN("usage_log"),
|
||||
|
||||
WRONG_PASSWORD("wrong_pwd"),
|
||||
|
||||
UNREGISTERED_SUCCESS("unregistered"),
|
||||
|
||||
REGISTRATION_DISABLED("reg_disabled"),
|
||||
|
||||
SESSION_RECONNECTION("valid_session"),
|
||||
|
||||
LOGIN_SUCCESS("login"),
|
||||
|
||||
ACCOUNT_NOT_ACTIVATED("vb_nonActiv"),
|
||||
|
||||
NAME_ALREADY_REGISTERED("user_regged"),
|
||||
|
||||
NO_PERMISSION("no_perm"),
|
||||
|
||||
ERROR("error"),
|
||||
|
||||
LOGIN_MESSAGE("login_msg"),
|
||||
|
||||
REGISTER_MESSAGE("reg_msg"),
|
||||
|
||||
REGISTER_EMAIL_MESSAGE("reg_email_msg"),
|
||||
|
||||
MAX_REGISTER_EXCEEDED("max_reg", "%max_acc", "%reg_count", "%reg_names"),
|
||||
|
||||
USAGE_REGISTER("usage_reg"),
|
||||
|
||||
USAGE_UNREGISTER("usage_unreg"),
|
||||
|
||||
PASSWORD_CHANGED_SUCCESS("pwd_changed"),
|
||||
|
||||
USER_NOT_REGISTERED("user_unknown"),
|
||||
|
||||
PASSWORD_MATCH_ERROR("password_error"),
|
||||
|
||||
PASSWORD_IS_USERNAME_ERROR("password_error_nick"),
|
||||
|
||||
PASSWORD_UNSAFE_ERROR("password_error_unsafe"),
|
||||
|
||||
PASSWORD_CHARACTERS_ERROR("password_error_chars", "REG_EX"),
|
||||
|
||||
SESSION_EXPIRED("invalid_session"),
|
||||
|
||||
MUST_REGISTER_MESSAGE("reg_only"),
|
||||
|
||||
ALREADY_LOGGED_IN_ERROR("logged_in"),
|
||||
|
||||
LOGOUT_SUCCESS("logout"),
|
||||
|
||||
USERNAME_ALREADY_ONLINE_ERROR("same_nick"),
|
||||
|
||||
REGISTER_SUCCESS("registered"),
|
||||
|
||||
INVALID_PASSWORD_LENGTH("pass_len"),
|
||||
|
||||
CONFIG_RELOAD_SUCCESS("reload"),
|
||||
|
||||
LOGIN_TIMEOUT_ERROR("timeout"),
|
||||
|
||||
USAGE_CHANGE_PASSWORD("usage_changepassword"),
|
||||
|
||||
INVALID_NAME_LENGTH("name_len"),
|
||||
|
||||
INVALID_NAME_CHARACTERS("regex", "REG_EX"),
|
||||
|
||||
ADD_EMAIL_MESSAGE("add_email"),
|
||||
|
||||
FORGOT_PASSWORD_MESSAGE("recovery_email"),
|
||||
|
||||
USAGE_CAPTCHA("usage_captcha", "<theCaptcha>"),
|
||||
|
||||
CAPTCHA_WRONG_ERROR("wrong_captcha", "THE_CAPTCHA"),
|
||||
|
||||
CAPTCHA_SUCCESS("valid_captcha"),
|
||||
|
||||
KICK_FOR_VIP("kick_forvip"),
|
||||
|
||||
KICK_FULL_SERVER("kick_fullserver"),
|
||||
|
||||
USAGE_ADD_EMAIL("usage_email_add"),
|
||||
|
||||
USAGE_CHANGE_EMAIL("usage_email_change"),
|
||||
|
||||
USAGE_RECOVER_EMAIL("usage_email_recovery"),
|
||||
|
||||
INVALID_NEW_EMAIL("new_email_invalid"),
|
||||
|
||||
INVALID_OLD_EMAIL("old_email_invalid"),
|
||||
|
||||
INVALID_EMAIL("email_invalid"),
|
||||
|
||||
EMAIL_ADDED_SUCCESS("email_added"),
|
||||
|
||||
CONFIRM_EMAIL_MESSAGE("email_confirm"),
|
||||
|
||||
EMAIL_CHANGED_SUCCESS("email_changed"),
|
||||
|
||||
RECOVERY_EMAIL_SENT_MESSAGE("email_send"),
|
||||
|
||||
RECOVERY_EMAIL_ALREADY_SENT_MESSAGE("email_exists"),
|
||||
|
||||
COUNTRY_BANNED_ERROR("country_banned"),
|
||||
|
||||
ANTIBOT_AUTO_ENABLED_MESSAGE("antibot_auto_enabled"),
|
||||
|
||||
ANTIBOT_AUTO_DISABLED_MESSAGE("antibot_auto_disabled", "%m"),
|
||||
|
||||
EMAIL_ALREADY_USED_ERROR("email_already_used"),
|
||||
|
||||
TWO_FACTOR_CREATE("two_factor_create", "%code", "%url"),
|
||||
|
||||
NOT_OWNER_ERROR("not_owner_error"),
|
||||
|
||||
INVALID_NAME_CASE("invalid_name_case", "%valid", "%invalid"),
|
||||
|
||||
TEMPBAN_MAX_LOGINS("tempban_max_logins"),
|
||||
|
||||
ACCOUNTS_OWNED_SELF("accounts_owned_self", "%count"),
|
||||
|
||||
ACCOUNTS_OWNED_OTHER("accounts_owned_other", "%name", "%count"),
|
||||
|
||||
KICK_FOR_ADMIN_REGISTER("kicked_admin_registered"),
|
||||
|
||||
INCOMPLETE_EMAIL_SETTINGS("incomplete_email_settings"),
|
||||
|
||||
RECOVERY_CODE_SENT("recovery_code_sent"),
|
||||
|
||||
INCORRECT_RECOVERY_CODE("recovery_code_incorrect");
|
||||
|
||||
private String key;
|
||||
private String[] tags;
|
||||
|
||||
MessageKey(String key, String... tags) {
|
||||
this.key = key;
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key used in the messages file.
|
||||
*
|
||||
* @return The key
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of tags (texts) that are replaced with actual content in AuthMe.
|
||||
*
|
||||
* @return List of tags
|
||||
*/
|
||||
public String[] getTags() {
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
package fr.xephi.authme.output;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Class for retrieving and sending translatable messages to players.
|
||||
*/
|
||||
public class Messages implements SettingsDependent {
|
||||
|
||||
// Custom Authme tag replaced to new line
|
||||
private static final String NEWLINE_TAG = "%nl%";
|
||||
|
||||
private FileConfiguration configuration;
|
||||
private String fileName;
|
||||
private final String defaultFile;
|
||||
private FileConfiguration defaultConfiguration;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param settings The settings
|
||||
*/
|
||||
@Inject
|
||||
Messages(Settings settings) {
|
||||
reload(settings);
|
||||
this.defaultFile = settings.getDefaultMessagesFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the given message code to the player with the given tag replacements. Note that this method
|
||||
* logs an error if the number of supplied replacements doesn't correspond to the number of tags
|
||||
* the message key contains.
|
||||
*
|
||||
* @param sender The entity to send the message to
|
||||
* @param key The key of the message to send
|
||||
* @param replacements The replacements to apply for the tags
|
||||
*/
|
||||
public void send(CommandSender sender, MessageKey key, String... replacements) {
|
||||
String message = retrieveSingle(key, replacements);
|
||||
for (String line : message.split("\n")) {
|
||||
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) {
|
||||
String message = retrieveMessage(key);
|
||||
if (message.isEmpty()) {
|
||||
// Return empty array instead of array with 1 empty string as entry
|
||||
return new String[0];
|
||||
}
|
||||
return message.split("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the message from the text file.
|
||||
*
|
||||
* @param key The message key to retrieve
|
||||
* @return The message from the file
|
||||
*/
|
||||
private String retrieveMessage(MessageKey key) {
|
||||
final String code = key.getKey();
|
||||
String message = configuration.getString(code);
|
||||
|
||||
if (message == null) {
|
||||
ConsoleLogger.warning("Error getting message with key '" + code + "'. "
|
||||
+ "Please verify your config file at '" + fileName + "'");
|
||||
return formatMessage(getDefault(code));
|
||||
}
|
||||
return formatMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the given message code with the given tag replacements. Note that this method
|
||||
* logs an error if the number of supplied replacements doesn't correspond to the number of tags
|
||||
* the message key contains.
|
||||
*
|
||||
* @param key The key of the message to send
|
||||
* @param replacements The replacements to apply for the tags
|
||||
* @return The message from the file with replacements
|
||||
*/
|
||||
public String retrieveSingle(MessageKey key, String... replacements) {
|
||||
String message = retrieveMessage(key);
|
||||
String[] tags = key.getTags();
|
||||
if (replacements.length == tags.length) {
|
||||
for (int i = 0; i < tags.length; ++i) {
|
||||
message = message.replace(tags[i], replacements[i]);
|
||||
}
|
||||
} else {
|
||||
ConsoleLogger.warning("Invalid number of replacements for message key '" + key + "'");
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload(Settings settings) {
|
||||
File messageFile = settings.getMessagesFile();
|
||||
this.configuration = YamlConfiguration.loadConfiguration(messageFile);
|
||||
this.fileName = messageFile.getName();
|
||||
}
|
||||
|
||||
private String getDefault(String code) {
|
||||
if (defaultFile == null) {
|
||||
return getDefaultErrorMessage(code);
|
||||
}
|
||||
|
||||
if (defaultConfiguration == null) {
|
||||
InputStream stream = Messages.class.getResourceAsStream(defaultFile);
|
||||
defaultConfiguration = YamlConfiguration.loadConfiguration(new InputStreamReader(stream));
|
||||
}
|
||||
String message = defaultConfiguration.getString(code);
|
||||
return message == null ? getDefaultErrorMessage(code) : message;
|
||||
}
|
||||
|
||||
private static String getDefaultErrorMessage(String code) {
|
||||
return "Error retrieving message '" + code + "'";
|
||||
}
|
||||
|
||||
private static String formatMessage(String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message)
|
||||
.replace(NEWLINE_TAG, "\n");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user