#427 Add message entry for each registration type

* Added message for /register password email
* Added messages for /register password and /register email commands
This commit is contained in:
koca2000 2016-12-23 14:39:43 +01:00 committed by ljacqu
parent 92f71d47c2
commit 4a2e0d4216
9 changed files with 49 additions and 36 deletions

View File

@ -64,9 +64,18 @@ public enum MessageKey {
/** Please, register to the server with the command "/register <password> <ConfirmPassword>" */ /** Please, register to the server with the command "/register <password> <ConfirmPassword>" */
REGISTER_MESSAGE("reg_msg"), REGISTER_MESSAGE("reg_msg"),
/** Please, register to the server with the command "/register <password>" */
REGISTER_NO_REPEAT_MESSAGE("reg_no_repeat_msg"),
/** Please, register to the server with the command "/register <email> <confirmEmail>" */ /** Please, register to the server with the command "/register <email> <confirmEmail>" */
REGISTER_EMAIL_MESSAGE("reg_email_msg"), REGISTER_EMAIL_MESSAGE("reg_email_msg"),
/** Please, register to the server with the command "/register <email>" */
REGISTER_EMAIL_NO_REPEAT_MESSAGE("reg_email_no_repeat_msg"),
/** Please, register to the server with the command "/register <password> <email>" */
REGISTER_PASSWORD_EMAIL_MESSAGE("reg_psw_email_msg"),
/** You have exceeded the maximum number of registrations (%reg_count/%max_acc %reg_names) for your connection! */ /** 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("max_reg", "%max_acc", "%reg_count", "%reg_names"),

View File

@ -1,5 +1,9 @@
package fr.xephi.authme.process.email; package fr.xephi.authme.process.email;
import javax.inject.Inject;
import org.bukkit.entity.Player;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
@ -9,10 +13,6 @@ import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RegistrationArgumentType.Execution;
import org.bukkit.entity.Player;
import javax.inject.Inject;
/** /**
* Async task to add an email to an account. * Async task to add an email to an account.
@ -64,10 +64,8 @@ public class AsyncAddEmail implements AsynchronousProcess {
private void sendUnloggedMessage(Player player) { private void sendUnloggedMessage(Player player) {
if (dataSource.isAuthAvailable(player.getName())) { if (dataSource.isAuthAvailable(player.getName())) {
service.send(player, MessageKey.LOGIN_MESSAGE); service.send(player, MessageKey.LOGIN_MESSAGE);
} else if (service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getExecution() == Execution.EMAIL) {
service.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
} else { } else {
service.send(player, MessageKey.REGISTER_MESSAGE); service.send(player, service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getMessageKey());
} }
} }

View File

@ -1,5 +1,9 @@
package fr.xephi.authme.process.email; package fr.xephi.authme.process.email;
import javax.inject.Inject;
import org.bukkit.entity.Player;
import fr.xephi.authme.data.auth.PlayerAuth; import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
@ -8,10 +12,6 @@ import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.service.CommonService; import fr.xephi.authme.service.CommonService;
import fr.xephi.authme.service.ValidationService; import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RegistrationArgumentType.Execution;
import org.bukkit.entity.Player;
import javax.inject.Inject;
/** /**
* Async task for changing the email. * Async task for changing the email.
@ -67,10 +67,8 @@ public class AsyncChangeEmail implements AsynchronousProcess {
private void outputUnloggedMessage(Player player) { private void outputUnloggedMessage(Player player) {
if (dataSource.isAuthAvailable(player.getName())) { if (dataSource.isAuthAvailable(player.getName())) {
service.send(player, MessageKey.LOGIN_MESSAGE); service.send(player, MessageKey.LOGIN_MESSAGE);
} else if (service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getExecution() == Execution.EMAIL) {
service.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
} else { } else {
service.send(player, MessageKey.REGISTER_MESSAGE); service.send(player, service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getMessageKey());
} }
} }
} }

View File

@ -1,27 +1,30 @@
package fr.xephi.authme.settings.properties; package fr.xephi.authme.settings.properties;
import fr.xephi.authme.message.MessageKey;
/** /**
* Type of arguments used for the login command. * Type of arguments used for the login command.
*/ */
public enum RegistrationArgumentType { public enum RegistrationArgumentType {
/** /register [password] */ /** /register [password] */
PASSWORD(Execution.PASSWORD, 1), PASSWORD(Execution.PASSWORD, 1, MessageKey.REGISTER_NO_REPEAT_MESSAGE),
/** /register [password] [password] */ /** /register [password] [password] */
PASSWORD_WITH_CONFIRMATION(Execution.PASSWORD, 2), PASSWORD_WITH_CONFIRMATION(Execution.PASSWORD, 2, MessageKey.REGISTER_MESSAGE),
/** /register [email] */ /** /register [email] */
EMAIL(Execution.EMAIL, 1), EMAIL(Execution.EMAIL, 1, MessageKey.REGISTER_EMAIL_NO_REPEAT_MESSAGE),
/** /register [email] [email] */ /** /register [email] [email] */
EMAIL_WITH_CONFIRMATION(Execution.EMAIL, 2), EMAIL_WITH_CONFIRMATION(Execution.EMAIL, 2, MessageKey.REGISTER_EMAIL_MESSAGE),
/** /register [password] [email] */ /** /register [password] [email] */
PASSWORD_WITH_EMAIL(Execution.PASSWORD, 2); PASSWORD_WITH_EMAIL(Execution.PASSWORD, 2, MessageKey.REGISTER_PASSWORD_EMAIL_MESSAGE);
private final Execution execution; private final Execution execution;
private final int requiredNumberOfArgs; private final int requiredNumberOfArgs;
private final MessageKey messageKey;
/** /**
* Constructor. * Constructor.
@ -29,9 +32,10 @@ public enum RegistrationArgumentType {
* @param execution the registration process * @param execution the registration process
* @param requiredNumberOfArgs the required number of arguments * @param requiredNumberOfArgs the required number of arguments
*/ */
RegistrationArgumentType(Execution execution, int requiredNumberOfArgs) { RegistrationArgumentType(Execution execution, int requiredNumberOfArgs, MessageKey messageKey) {
this.execution = execution; this.execution = execution;
this.requiredNumberOfArgs = requiredNumberOfArgs; this.requiredNumberOfArgs = requiredNumberOfArgs;
this.messageKey = messageKey;
} }
/** /**
@ -40,6 +44,10 @@ public enum RegistrationArgumentType {
public Execution getExecution() { public Execution getExecution() {
return execution; return execution;
} }
public MessageKey getMessageKey(){
return messageKey;
}
/** /**
* @return number of arguments required to process the register command * @return number of arguments required to process the register command
@ -55,6 +63,5 @@ public enum RegistrationArgumentType {
PASSWORD, PASSWORD,
EMAIL EMAIL
} }
} }

View File

@ -1,5 +1,13 @@
package fr.xephi.authme.task; package fr.xephi.authme.task;
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
import javax.inject.Inject;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.data.auth.PlayerCache; import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboCache; import fr.xephi.authme.data.limbo.LimboCache;
@ -9,15 +17,7 @@ import fr.xephi.authme.message.Messages;
import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RegistrationArgumentType.Execution;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import javax.inject.Inject;
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
/** /**
* Registers tasks associated with a PlayerData. * Registers tasks associated with a PlayerData.
@ -96,9 +96,7 @@ public class LimboPlayerTaskManager {
if (isRegistered) { if (isRegistered) {
return MessageKey.LOGIN_MESSAGE; return MessageKey.LOGIN_MESSAGE;
} else { } else {
return settings.getProperty(RegistrationSettings.REGISTRATION_TYPE).getExecution() == Execution.EMAIL return settings.getProperty(RegistrationSettings.REGISTRATION_TYPE).getMessageKey();
? MessageKey.REGISTER_EMAIL_MESSAGE
: MessageKey.REGISTER_MESSAGE;
} }
} }

View File

@ -20,7 +20,10 @@ no_perm: '&4You don''t have the permission to perform this action!'
error: '&4An unexpected error occurred, please contact an administrator!' error: '&4An unexpected error occurred, please contact an administrator!'
login_msg: '&cPlease, login with the command "/login <password>"' login_msg: '&cPlease, login with the command "/login <password>"'
reg_msg: '&3Please, register to the server with the command "/register <password> <ConfirmPassword>"' reg_msg: '&3Please, register to the server with the command "/register <password> <ConfirmPassword>"'
reg_no_repeat_msg: '&3Please, register to the server with the command "/register <password>"'
reg_email_msg: '&3Please, register to the server with the command "/register <email> <confirmEmail>"' reg_email_msg: '&3Please, register to the server with the command "/register <email> <confirmEmail>"'
reg_email_no_repeat_msg: '&3Please, register to the server with the command "/register <email>"'
reg_psw_email_msg: '&3Please, register to the server with the command "/register <password> <email>"'
usage_unreg: '&cUsage: /unregister <password>' usage_unreg: '&cUsage: /unregister <password>'
pwd_changed: '&2Password changed successfully!' pwd_changed: '&2Password changed successfully!'
user_unknown: '&cThis user isn''t registered!' user_unknown: '&cThis user isn''t registered!'

View File

@ -179,7 +179,7 @@ public class AsyncAddEmailTest {
asyncAddEmail.addEmail(player, "test@mail.com"); asyncAddEmail.addEmail(player, "test@mail.com");
// then // then
verify(service).send(player, MessageKey.REGISTER_EMAIL_MESSAGE); verify(service).send(player, MessageKey.REGISTER_EMAIL_NO_REPEAT_MESSAGE);
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class)); verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
} }

View File

@ -210,7 +210,7 @@ public class AsyncChangeEmailTest {
// then // then
verify(dataSource, never()).updateEmail(any(PlayerAuth.class)); verify(dataSource, never()).updateEmail(any(PlayerAuth.class));
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class)); verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
verify(service).send(player, MessageKey.REGISTER_MESSAGE); verify(service).send(player, MessageKey.REGISTER_NO_REPEAT_MESSAGE);
} }
private static PlayerAuth authWithMail(String email) { private static PlayerAuth authWithMail(String email) {

View File

@ -120,7 +120,7 @@ public class LimboPlayerTaskManagerTest {
String name = "bobby"; String name = "bobby";
given(limboCache.getPlayerData(name)).willReturn(limboPlayer); given(limboCache.getPlayerData(name)).willReturn(limboPlayer);
given(messages.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE)) given(messages.retrieve(MessageKey.REGISTER_EMAIL_NO_REPEAT_MESSAGE))
.willReturn(new String[]{"Please register", "Use /register"}); .willReturn(new String[]{"Please register", "Use /register"});
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8); given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
@ -131,7 +131,7 @@ public class LimboPlayerTaskManagerTest {
// then // then
verify(limboPlayer).setMessageTask(any(MessageTask.class)); verify(limboPlayer).setMessageTask(any(MessageTask.class));
verify(messages).retrieve(MessageKey.REGISTER_EMAIL_MESSAGE); verify(messages).retrieve(MessageKey.REGISTER_EMAIL_NO_REPEAT_MESSAGE);
verify(existingMessageTask).cancel(); verify(existingMessageTask).cancel();
} }