#797 Make two messages translatable

This commit is contained in:
ljacqu 2016-07-02 21:49:01 +02:00
parent 9a5c432509
commit 3984208548
8 changed files with 25 additions and 9 deletions

View File

@ -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.
*

View File

@ -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));
}
});
}

View File

@ -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)) {

View File

@ -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<String> 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;

View File

@ -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;

View File

@ -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.'

View File

@ -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) {

View File

@ -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);
}