#723 Let LimboPlayer task manager decide which message key to use

- Pass boolean (is registered) value and determine internally which message key (email registration vs. regular) to use in the message task
This commit is contained in:
ljacqu
2016-06-15 20:37:00 +02:00
parent 5cbb83e153
commit 15886fb517
9 changed files with 37 additions and 36 deletions
@@ -44,10 +44,12 @@ public class LimboPlayerTaskManager {
* Registers a {@link MessageTask} for the given player name.
*
* @param name the name of the player to schedule a repeating message task for
* @param key the key of the message to display
* @param isRegistered whether the name is registered or not
* (false shows "please register", true shows "please log in")
*/
public void registerMessageTask(String name, MessageKey key) {
public void registerMessageTask(String name, boolean isRegistered) {
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
final MessageKey key = getMessageKey(isRegistered);
if (interval > 0) {
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
if (limboPlayer == null) {
@@ -81,6 +83,22 @@ public class LimboPlayerTaskManager {
}
}
/**
* Returns the appropriate message key according to the registration status and settings.
*
* @param isRegistered whether or not the username is registered
* @return the message key to display to the user
*/
private MessageKey getMessageKey(boolean isRegistered) {
if (isRegistered) {
return MessageKey.LOGIN_MESSAGE;
} else {
return settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
? MessageKey.REGISTER_EMAIL_MESSAGE
: MessageKey.REGISTER_MESSAGE;
}
}
/**
* Null-safe method to cancel a potentially existing task.
*