diff --git a/src/main/java/fr/xephi/authme/command/CommandService.java b/src/main/java/fr/xephi/authme/command/CommandService.java index 5efe79e80..5114d1ffc 100644 --- a/src/main/java/fr/xephi/authme/command/CommandService.java +++ b/src/main/java/fr/xephi/authme/command/CommandService.java @@ -53,6 +53,16 @@ public class CommandService { return messages.retrieve(key); } + /** + * Retrieve a message as a single String by its message key. + * + * @param key The message to retrieve + * @return The message + */ + public String retrieveSingle(MessageKey key) { + return messages.retrieveSingle(key); + } + /** * Retrieve the given property's value. * diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java index a4931e963..deddaf9c7 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java @@ -79,7 +79,7 @@ public class RegisterAdminCommand implements ExecutableCommand { bukkitService.scheduleSyncDelayedTask(new Runnable() { @Override public void run() { - player.kickPlayer("An admin just registered you, please log in again"); + player.kickPlayer(commandService.retrieveSingle(MessageKey.KICK_FOR_ADMIN_REGISTER)); } }); } 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 8a874af7e..346b90722 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 @@ -42,7 +42,7 @@ public class RecoverEmailCommand extends PlayerCommand { if (!sendMailSsl.hasAllInformation()) { ConsoleLogger.showError("Mail API is not set"); - commandService.send(player, MessageKey.ERROR); + commandService.send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS); return; } if (dataSource.isAuthAvailable(playerName)) { 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 cb8c1946c..be8b1edb3 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 @@ -15,6 +15,7 @@ import org.bukkit.entity.Player; import javax.inject.Inject; import java.util.List; +import static fr.xephi.authme.output.MessageKey.INCOMPLETE_EMAIL_SETTINGS; import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH; import static fr.xephi.authme.settings.properties.RegistrationSettings.ENABLE_CONFIRM_EMAIL; import static fr.xephi.authme.settings.properties.RegistrationSettings.USE_EMAIL_REGISTRATION; @@ -68,8 +69,7 @@ public class RegisterCommand extends PlayerCommand { private void handleEmailRegistration(Player player, List arguments) { if (!sendMailSsl.hasAllInformation()) { - player.sendMessage("Cannot register: not all required settings are set for sending emails. " - + "Please contact an administrator"); + commandService.send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS); ConsoleLogger.showError("Cannot register player '" + player.getName() + "': no email or password is set " + "to send emails from. Please adjust your config at " + EmailSettings.MAIL_ACCOUNT.getPath()); return; diff --git a/src/main/java/fr/xephi/authme/output/MessageKey.java b/src/main/java/fr/xephi/authme/output/MessageKey.java index 670366f50..c445b9a2d 100644 --- a/src/main/java/fr/xephi/authme/output/MessageKey.java +++ b/src/main/java/fr/xephi/authme/output/MessageKey.java @@ -143,7 +143,11 @@ public enum MessageKey { ACCOUNTS_OWNED_SELF("accounts_owned_self", "%count"), - ACCOUNTS_OWNED_OTHER("accounts_owned_other", "%name", "%count"); + ACCOUNTS_OWNED_OTHER("accounts_owned_other", "%name", "%count"), + + KICK_FOR_ADMIN_REGISTER("kicked_admin_registered"), + + INCOMPLETE_EMAIL_SETTINGS("incomplete_email_settings"); private String key; private String[] tags; diff --git a/src/main/resources/messages/messages_en.yml b/src/main/resources/messages/messages_en.yml index f2926eb92..b02a2c985 100644 --- a/src/main/resources/messages/messages_en.yml +++ b/src/main/resources/messages/messages_en.yml @@ -68,3 +68,5 @@ invalid_name_case: 'You should join using username %valid, not %invalid.' tempban_max_logins: '&cYou have been temporarily banned for failing to log in too many times.' accounts_owned_self: 'You own %count accounts:' accounts_owned_other: 'The player %name has %count accounts:' +kicked_admin_registered: 'An admin just registered you; please log in again' +incomplete_email_settings: 'Error: not all required settings are set for sending emails. Please contact an admin.' diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java index d6d0924e7..441a38a24 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java @@ -22,12 +22,10 @@ import org.mockito.runners.MockitoJUnitRunner; import java.util.Arrays; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -160,6 +158,8 @@ public class RegisterAdminCommandTest { given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword); Player player = mock(Player.class); given(bukkitService.getPlayerExact(user)).willReturn(player); + String kickForAdminRegister = "Admin registered you -- log in again"; + given(commandService.retrieveSingle(MessageKey.KICK_FOR_ADMIN_REGISTER)).willReturn(kickForAdminRegister); CommandSender sender = mock(CommandSender.class); // when @@ -174,7 +174,7 @@ public class RegisterAdminCommandTest { verify(dataSource).saveAuth(captor.capture()); assertAuthHasInfo(captor.getValue(), user, hashedPassword); verify(dataSource).setUnlogged(user); - verify(player).kickPlayer(argThat(containsString("please log in again"))); + verify(player).kickPlayer(kickForAdminRegister); } private void assertAuthHasInfo(PlayerAuth auth, String name, HashedPassword hashedPassword) { 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 683302dbf..dd30d9705 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 @@ -146,7 +146,7 @@ public class RegisterCommandTest { command.executeCommand(player, Collections.singletonList("myMail@example.tld")); // then - verify(player).sendMessage(argThat(containsString("not all required settings are set for sending emails"))); + verify(commandService).send(player, MessageKey.INCOMPLETE_EMAIL_SETTINGS); verify(sendMailSsl).hasAllInformation(); verifyZeroInteractions(management); }