mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-11 10:27:36 +01:00
#797 Make two messages translatable
This commit is contained in:
parent
9a5c432509
commit
3984208548
@ -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.
|
||||
*
|
||||
|
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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.'
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user