#1467 Change message keys and messages_en to new structure

This commit is contained in:
ljacqu
2018-01-29 20:56:30 +01:00
parent dfe47066cd
commit f714e9d564
4 changed files with 257 additions and 197 deletions
@@ -6,298 +6,298 @@ package fr.xephi.authme.message;
public enum MessageKey {
/** In order to use this command you must be authenticated! */
DENIED_COMMAND("denied_command"),
DENIED_COMMAND("error.denied_command"),
/** A player with the same IP is already in game! */
SAME_IP_ONLINE("same_ip_online"),
SAME_IP_ONLINE("on_join_validation.same_ip_online"),
/** In order to chat you must be authenticated! */
DENIED_CHAT("denied_chat"),
DENIED_CHAT("error.denied_chat"),
/** AntiBot protection mode is enabled! You have to wait some minutes before joining the server. */
KICK_ANTIBOT("kick_antibot"),
KICK_ANTIBOT("antibot.kick_antibot"),
/** This user isn't registered! */
UNKNOWN_USER("unknown_user"),
UNKNOWN_USER("error.unregistered_user"),
/** You're not logged in! */
NOT_LOGGED_IN("not_logged_in"),
NOT_LOGGED_IN("error.not_logged_in"),
/** Usage: /login <password> */
USAGE_LOGIN("usage_log"),
USAGE_LOGIN("login.command_usage"),
/** Wrong password! */
WRONG_PASSWORD("wrong_pwd"),
WRONG_PASSWORD("login.wrong_password"),
/** Successfully unregistered! */
UNREGISTERED_SUCCESS("unregistered"),
UNREGISTERED_SUCCESS("unregister.success"),
/** In-game registration is disabled! */
REGISTRATION_DISABLED("reg_disabled"),
REGISTRATION_DISABLED("registration.disabled"),
/** Logged-in due to Session Reconnection. */
SESSION_RECONNECTION("valid_session"),
SESSION_RECONNECTION("session.valid_session"),
/** Successful login! */
LOGIN_SUCCESS("login"),
LOGIN_SUCCESS("login.success"),
/** Your account isn't activated yet, please check your emails! */
ACCOUNT_NOT_ACTIVATED("vb_nonActiv"),
ACCOUNT_NOT_ACTIVATED("misc.account_not_activated"),
/** You already have registered this username! */
NAME_ALREADY_REGISTERED("user_regged"),
NAME_ALREADY_REGISTERED("registration.name_taken"),
/** You don't have the permission to perform this action! */
NO_PERMISSION("no_perm"),
NO_PERMISSION("error.no_permission"),
/** An unexpected error occurred, please contact an administrator! */
ERROR("error"),
ERROR("error.unexpected_error"),
/** Please, login with the command: /login <password> */
LOGIN_MESSAGE("login_msg"),
LOGIN_MESSAGE("login.login_request"),
/** Please, register to the server with the command: /register <password> <ConfirmPassword> */
REGISTER_MESSAGE("reg_msg"),
REGISTER_MESSAGE("registration.register_request"),
/** You have exceeded the maximum number of registrations (%reg_count/%max_acc %reg_names) for your connection! */
MAX_REGISTER_EXCEEDED("max_reg", "%max_acc", "%reg_count", "%reg_names"),
MAX_REGISTER_EXCEEDED("error.max_registration", "%max_acc", "%reg_count", "%reg_names"),
/** Usage: /register <password> <ConfirmPassword> */
USAGE_REGISTER("usage_reg"),
USAGE_REGISTER("registration.command_usage"),
/** Usage: /unregister <password> */
USAGE_UNREGISTER("usage_unreg"),
USAGE_UNREGISTER("unregister.command_usage"),
/** Password changed successfully! */
PASSWORD_CHANGED_SUCCESS("pwd_changed"),
PASSWORD_CHANGED_SUCCESS("misc.password_changed"),
/** Passwords didn't match, check them again! */
PASSWORD_MATCH_ERROR("password_error"),
PASSWORD_MATCH_ERROR("password.match_error"),
/** You can't use your name as password, please choose another one... */
PASSWORD_IS_USERNAME_ERROR("password_error_nick"),
PASSWORD_IS_USERNAME_ERROR("password.name_in_password"),
/** The chosen password isn't safe, please choose another one... */
PASSWORD_UNSAFE_ERROR("password_error_unsafe"),
PASSWORD_UNSAFE_ERROR("password.unsafe_password"),
/** Your password contains illegal characters. Allowed chars: REG_EX */
PASSWORD_CHARACTERS_ERROR("password_error_chars", "REG_EX"),
/** Your password contains illegal characters. Allowed chars: %valid_chars */
PASSWORD_CHARACTERS_ERROR("password.forbidden_characters", "%valid_chars"),
/** Your IP has been changed and your session data has expired! */
SESSION_EXPIRED("invalid_session"),
SESSION_EXPIRED("session.invalid_session"),
/** Only registered users can join the server! Please visit http://example.com to register yourself! */
MUST_REGISTER_MESSAGE("reg_only"),
MUST_REGISTER_MESSAGE("registration.reg_only"),
/** You're already logged in! */
ALREADY_LOGGED_IN_ERROR("logged_in"),
ALREADY_LOGGED_IN_ERROR("error.logged_in"),
/** Logged out successfully! */
LOGOUT_SUCCESS("logout"),
LOGOUT_SUCCESS("misc.logout"),
/** The same username is already playing on the server! */
USERNAME_ALREADY_ONLINE_ERROR("same_nick"),
USERNAME_ALREADY_ONLINE_ERROR("on_join_validation.same_nick_online"),
/** Successfully registered! */
REGISTER_SUCCESS("registered"),
REGISTER_SUCCESS("registration.success"),
/** Your password is too short or too long! Please try with another one! */
INVALID_PASSWORD_LENGTH("pass_len"),
INVALID_PASSWORD_LENGTH("password.wrong_length"),
/** Configuration and database have been reloaded correctly! */
CONFIG_RELOAD_SUCCESS("reload"),
CONFIG_RELOAD_SUCCESS("misc.reload"),
/** Login timeout exceeded, you have been kicked from the server, please try again! */
LOGIN_TIMEOUT_ERROR("timeout"),
LOGIN_TIMEOUT_ERROR("login.timeout_error"),
/** Usage: /changepassword <oldPassword> <newPassword> */
USAGE_CHANGE_PASSWORD("usage_changepassword"),
USAGE_CHANGE_PASSWORD("misc.usage_change_password"),
/** Your username is either too short or too long! */
INVALID_NAME_LENGTH("name_len"),
INVALID_NAME_LENGTH("on_join_validation.name_length"),
/** Your username contains illegal characters. Allowed chars: REG_EX */
INVALID_NAME_CHARACTERS("regex", "REG_EX"),
/** Your username contains illegal characters. Allowed chars: %valid_chars */
INVALID_NAME_CHARACTERS("on_join_validation.characters_in_name", "%valid_chars"),
/** Please add your email to your account with the command: /email add <yourEmail> <confirmEmail> */
ADD_EMAIL_MESSAGE("add_email"),
ADD_EMAIL_MESSAGE("email.add_email_request"),
/** Forgot your password? Please use the command: /email recovery <yourEmail> */
FORGOT_PASSWORD_MESSAGE("recovery_email"),
FORGOT_PASSWORD_MESSAGE("recovery.forgot_password_hint"),
/** To login you have to solve a captcha code, please use the command: /captcha <theCaptcha> */
USAGE_CAPTCHA("usage_captcha", "<theCaptcha>"),
/** To login you have to solve a captcha code, please use the command: /captcha %captcha_code */
USAGE_CAPTCHA("captcha.usage_captcha", "%captcha_code"),
/** Wrong captcha, please type "/captcha THE_CAPTCHA" into the chat! */
CAPTCHA_WRONG_ERROR("wrong_captcha", "THE_CAPTCHA"),
/** Wrong captcha, please type "/captcha %captcha_code" into the chat! */
CAPTCHA_WRONG_ERROR("captcha.wrong_captcha", "%captcha_code"),
/** Captcha code solved correctly! */
CAPTCHA_SUCCESS("valid_captcha"),
CAPTCHA_SUCCESS("captcha.valid_captcha"),
/** To register you have to solve a captcha code first, please use the command: /captcha &lt;theCaptcha&gt; */
CAPTCHA_FOR_REGISTRATION_REQUIRED("captcha_for_registration", "<theCaptcha>"),
/** To register you have to solve a captcha code first, please use the command: /captcha %captcha_code */
CAPTCHA_FOR_REGISTRATION_REQUIRED("captcha.captcha_for_registration", "%captcha_code"),
/** Valid captcha! You may now register with /register */
REGISTER_CAPTCHA_SUCCESS("register_captcha_valid"),
REGISTER_CAPTCHA_SUCCESS("captcha.register_captcha_valid"),
/** A VIP player has joined the server when it was full! */
KICK_FOR_VIP("kick_forvip"),
KICK_FOR_VIP("error.kick_for_vip"),
/** The server is full, try again later! */
KICK_FULL_SERVER("kick_fullserver"),
KICK_FULL_SERVER("on_join_validation.kick_full_server"),
/** Usage: /email add &lt;email&gt; &lt;confirmEmail&gt; */
USAGE_ADD_EMAIL("usage_email_add"),
USAGE_ADD_EMAIL("email.usage_email_add"),
/** Usage: /email change &lt;oldEmail&gt; &lt;newEmail&gt; */
USAGE_CHANGE_EMAIL("usage_email_change"),
USAGE_CHANGE_EMAIL("email.usage_email_change"),
/** Usage: /email recovery &lt;Email&gt; */
USAGE_RECOVER_EMAIL("usage_email_recovery"),
USAGE_RECOVER_EMAIL("recovery.command_usage"),
/** Invalid new email, try again! */
INVALID_NEW_EMAIL("new_email_invalid"),
INVALID_NEW_EMAIL("email.new_email_invalid"),
/** Invalid old email, try again! */
INVALID_OLD_EMAIL("old_email_invalid"),
INVALID_OLD_EMAIL("email.old_email_invalid"),
/** Invalid email address, try again! */
INVALID_EMAIL("email_invalid"),
INVALID_EMAIL("email.invalid"),
/** Email address successfully added to your account! */
EMAIL_ADDED_SUCCESS("email_added"),
EMAIL_ADDED_SUCCESS("email.added"),
/** Please confirm your email address! */
CONFIRM_EMAIL_MESSAGE("email_confirm"),
CONFIRM_EMAIL_MESSAGE("email.request_confirmation"),
/** Email address changed correctly! */
EMAIL_CHANGED_SUCCESS("email_changed"),
EMAIL_CHANGED_SUCCESS("email.changed"),
/** Your current email address is: %email */
EMAIL_SHOW("email_show", "%email"),
EMAIL_SHOW("email.email_show", "%email"),
/** You currently don't have email address associated with this account. */
SHOW_NO_EMAIL("show_no_email"),
SHOW_NO_EMAIL("email.no_email_for_account"),
/** Recovery email sent successfully! Please check your email inbox! */
RECOVERY_EMAIL_SENT_MESSAGE("email_send"),
RECOVERY_EMAIL_SENT_MESSAGE("recovery.email_sent"),
/** Your country is banned from this server! */
COUNTRY_BANNED_ERROR("country_banned"),
COUNTRY_BANNED_ERROR("on_join_validation.country_banned"),
/** [AntiBotService] AntiBot enabled due to the huge number of connections! */
ANTIBOT_AUTO_ENABLED_MESSAGE("antibot_auto_enabled"),
ANTIBOT_AUTO_ENABLED_MESSAGE("antibot.auto_enabled"),
/** [AntiBotService] AntiBot disabled after %m minutes! */
ANTIBOT_AUTO_DISABLED_MESSAGE("antibot_auto_disabled", "%m"),
ANTIBOT_AUTO_DISABLED_MESSAGE("antibot.auto_disabled", "%m"),
/** The email address is already being used */
EMAIL_ALREADY_USED_ERROR("email_already_used"),
EMAIL_ALREADY_USED_ERROR("email.already_used"),
/** Your secret code is %code. You can scan it from here %url */
TWO_FACTOR_CREATE("two_factor_create", "%code", "%url"),
TWO_FACTOR_CREATE("misc.two_factor_create", "%code", "%url"),
/** You are not the owner of this account. Please choose another name! */
NOT_OWNER_ERROR("not_owner_error"),
NOT_OWNER_ERROR("on_join_validation.not_owner_error"),
/** You should join using username %valid, not %invalid. */
INVALID_NAME_CASE("invalid_name_case", "%valid", "%invalid"),
INVALID_NAME_CASE("on_join_validation.invalid_name_case", "%valid", "%invalid"),
/** You have been temporarily banned for failing to log in too many times. */
TEMPBAN_MAX_LOGINS("tempban_max_logins"),
TEMPBAN_MAX_LOGINS("error.tempban_max_logins"),
/** You own %count accounts: */
ACCOUNTS_OWNED_SELF("accounts_owned_self", "%count"),
ACCOUNTS_OWNED_SELF("misc.accounts_owned_self", "%count"),
/** The player %name has %count accounts: */
ACCOUNTS_OWNED_OTHER("accounts_owned_other", "%name", "%count"),
ACCOUNTS_OWNED_OTHER("misc.accounts_owned_other", "%name", "%count"),
/** An admin just registered you; please log in again */
KICK_FOR_ADMIN_REGISTER("kicked_admin_registered"),
KICK_FOR_ADMIN_REGISTER("registration.kicked_admin_registered"),
/** Error: not all required settings are set for sending emails. Please contact an admin. */
INCOMPLETE_EMAIL_SETTINGS("incomplete_email_settings"),
INCOMPLETE_EMAIL_SETTINGS("email.incomplete_settings"),
/** The email could not be sent. Please contact an administrator. */
EMAIL_SEND_FAILURE("email_send_failure"),
EMAIL_SEND_FAILURE("email.send_failure"),
/** A recovery code to reset your password has been sent to your email. */
RECOVERY_CODE_SENT("recovery_code_sent"),
RECOVERY_CODE_SENT("recovery.code.code_sent"),
/** The recovery code is not correct! You have %count tries remaining. */
INCORRECT_RECOVERY_CODE("recovery_code_incorrect", "%count"),
INCORRECT_RECOVERY_CODE("recovery.code.incorrect", "%count"),
/**
* You have exceeded the maximum number of attempts to enter the recovery code.
* Use "/email recovery [email]" to generate a new one.
*/
RECOVERY_TRIES_EXCEEDED("recovery_tries_exceeded"),
RECOVERY_TRIES_EXCEEDED("recovery.code.tries_exceeded"),
/** Recovery code entered correctly! */
RECOVERY_CODE_CORRECT("recovery_code_correct"),
RECOVERY_CODE_CORRECT("recovery.code.correct"),
/** Please use the command /email setpassword to change your password immediately. */
RECOVERY_CHANGE_PASSWORD("recovery_change_password"),
RECOVERY_CHANGE_PASSWORD("recovery.code.change_password"),
/** You cannot change your password using this command anymore. */
CHANGE_PASSWORD_EXPIRED("change_password_expired"),
CHANGE_PASSWORD_EXPIRED("email.change_password_expired"),
/** An email was already sent recently. You must wait %time before you can send a new one. */
EMAIL_COOLDOWN_ERROR("email_cooldown_error", "%time"),
EMAIL_COOLDOWN_ERROR("email.email_cooldown_error", "%time"),
/**
* The command you are trying to execute is sensitive and requires a verification!
* A verification code has been sent to your email,
* run the command "/verification [code]" to verify your identity.
*/
VERIFICATION_CODE_REQUIRED("verification_code_required"),
VERIFICATION_CODE_REQUIRED("verification.code_required"),
/** Usage: /verification &lt;code&gt; */
USAGE_VERIFICATION_CODE("usage_verification_code"),
USAGE_VERIFICATION_CODE("verification.command_usage"),
/** Incorrect code, please type "/verification &lt;code&gt;" into the chat! */
INCORRECT_VERIFICATION_CODE("incorrect_verification_code"),
INCORRECT_VERIFICATION_CODE("verification.incorrect_code"),
/**
* Your identity has been verified!
* You can now execute every sensitive command within the current session!
*/
VERIFICATION_CODE_VERIFIED("verification_code_verified"),
VERIFICATION_CODE_VERIFIED("verification.success"),
/**
* You can already execute every sensitive command within the current session!
*/
VERIFICATION_CODE_ALREADY_VERIFIED("verification_code_already_verified"),
VERIFICATION_CODE_ALREADY_VERIFIED("verification.already_verified"),
/** Your code has expired! Execute another sensitive command to get a new code! */
VERIFICATION_CODE_EXPIRED("verification_code_expired"),
VERIFICATION_CODE_EXPIRED("verification.code_expired"),
/** To verify your identity you need to link an email address with your account! */
VERIFICATION_CODE_EMAIL_NEEDED("verification_code_email_needed"),
VERIFICATION_CODE_EMAIL_NEEDED("verification.email_needed"),
/** second */
SECOND("second"),
SECOND("time.second"),
/** seconds */
SECONDS("seconds"),
SECONDS("time.seconds"),
/** minute */
MINUTE("minute"),
MINUTE("time.minute"),
/** minutes */
MINUTES("minutes"),
MINUTES("time.minutes"),
/** hour */
HOUR("hour"),
HOUR("time.hour"),
/** hours */
HOURS("hours"),
HOURS("time.hours"),
/** day */
DAY("day"),
DAY("time.day"),
/** days */
DAYS("days");
DAYS("time.days");
private String key;
@@ -6,6 +6,8 @@ import fr.xephi.authme.message.MessageKey;
import java.util.Map;
import static com.google.common.collect.ImmutableMap.of;
/**
* Migrates message files from the old keys (before 5.5) to the new ones.
*
@@ -13,6 +15,15 @@ import java.util.Map;
*/
final class OldMessageKeysMigrater {
private static final Map<MessageKey, Map<String, String>> PLACEHOLDER_REPLACEMENTS =
ImmutableMap.<MessageKey, Map<String, String>>builder()
.put(MessageKey.PASSWORD_CHARACTERS_ERROR, of("REG_EX", "%valid_chars"))
.put(MessageKey.INVALID_NAME_CHARACTERS, of("REG_EX", "%valid_chars"))
.put(MessageKey.USAGE_CAPTCHA, of("<theCaptcha>", "%captcha_code"))
.put(MessageKey.CAPTCHA_FOR_REGISTRATION_REQUIRED, of("<theCaptcha>", "%captcha_code"))
.put(MessageKey.CAPTCHA_WRONG_ERROR, of("THE_CAPTCHA", "%captcha_code"))
.build();
private static final Map<MessageKey, String> KEYS_TO_OLD_PATH = ImmutableMap.<MessageKey, String>builder()
.put(MessageKey.DENIED_COMMAND, "denied_command")
.put(MessageKey.SAME_IP_ONLINE, "same_ip_online")
@@ -122,19 +133,33 @@ final class OldMessageKeysMigrater {
static boolean migrateOldPaths(PropertyResource resource) {
boolean wasPropertyMoved = false;
for (Map.Entry<MessageKey, String> migrationEntry : KEYS_TO_OLD_PATH.entrySet()) {
wasPropertyMoved |= moveIfApplicable(resource, migrationEntry.getKey().getKey(), migrationEntry.getValue());
wasPropertyMoved |= moveIfApplicable(resource, migrationEntry.getKey(), migrationEntry.getValue());
}
return wasPropertyMoved;
}
private static boolean moveIfApplicable(PropertyResource resource, String newPath, String oldPath) {
if (resource.getString(newPath) == null) {
private static boolean moveIfApplicable(PropertyResource resource, MessageKey messageKey, String oldPath) {
if (resource.getString(messageKey.getKey()) == null) {
String textAtOldPath = resource.getString(oldPath);
if (textAtOldPath != null) {
resource.setValue(newPath, textAtOldPath);
textAtOldPath = replaceOldPlaceholders(messageKey, textAtOldPath);
resource.setValue(messageKey.getKey(), textAtOldPath);
return true;
}
}
return false;
}
private static String replaceOldPlaceholders(MessageKey key, String text) {
Map<String, String> replacements = PLACEHOLDER_REPLACEMENTS.get(key);
if (replacements == null) {
return text;
}
String newText = text;
for (Map.Entry<String, String> replacement : replacements.entrySet()) {
text = text.replace(replacement.getKey(), replacement.getValue());
}
return newText;
}
}