#1116 #1117 Add command usage hints and remove unused message keys

- Add usage message on argument mismatch where available
- Remove unused message keys
- Create tool task to search for a message key's usages and to find unused keys
This commit is contained in:
ljacqu
2017-03-24 23:03:10 +01:00
parent 2f90a45f43
commit a2d62ea6d9
41 changed files with 155 additions and 74 deletions
@@ -19,7 +19,7 @@ public interface ExecutableCommand {
void executeCommand(CommandSender sender, List<String> arguments);
/**
* Returns the message to show to the user if the command is used with the wrong commands.
* Returns the message to show to the user if the command is used with the wrong arguments.
* If null is returned, the standard help (/<i>command</i> help) output is shown.
*
* @return the message explaining the command's usage, or {@code null} for default behavior
@@ -54,4 +54,9 @@ public class ChangePasswordCommand extends PlayerCommand {
protected String getAlternativeCommand() {
return "/authme password <playername> <password>";
}
@Override
public MessageKey getArgumentsMismatchMessage() {
return MessageKey.USAGE_CHANGE_PASSWORD;
}
}
@@ -32,4 +32,9 @@ public class AddEmailCommand extends PlayerCommand {
commonService.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
}
}
@Override
public MessageKey getArgumentsMismatchMessage() {
return MessageKey.USAGE_ADD_EMAIL;
}
}
@@ -1,6 +1,7 @@
package fr.xephi.authme.command.executable.email;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.process.Management;
import org.bukkit.entity.Player;
@@ -22,4 +23,9 @@ public class ChangeEmailCommand extends PlayerCommand {
management.performChangeEmail(player, playerMailOld, playerMailNew);
}
@Override
public MessageKey getArgumentsMismatchMessage() {
return MessageKey.USAGE_CHANGE_EMAIL;
}
}
@@ -53,7 +53,7 @@ public class RecoverEmailCommand extends PlayerCommand {
return;
}
PlayerAuth auth = dataSource.getAuth(playerName); // TODO: Create method to get email only
PlayerAuth auth = dataSource.getAuth(playerName); // TODO #1127: Create method to get email only
if (auth == null) {
commonService.send(player, MessageKey.USAGE_REGISTER);
return;
@@ -73,4 +73,9 @@ public class RecoverEmailCommand extends PlayerCommand {
recoveryService.generateAndSendNewPassword(player, email);
}
}
@Override
public MessageKey getArgumentsMismatchMessage() {
return MessageKey.USAGE_RECOVER_EMAIL;
}
}
@@ -38,4 +38,14 @@ public class UnregisterCommand extends PlayerCommand {
// Unregister the player
management.performUnregister(player, playerPass);
}
@Override
public MessageKey getArgumentsMismatchMessage() {
return MessageKey.USAGE_UNREGISTER;
}
@Override
protected String getAlternativeCommand() {
return "/authme unregister <player>";
}
}
@@ -20,9 +20,6 @@ public enum MessageKey {
/** This user isn't registered! */
UNKNOWN_USER("unknown_user"),
/** Your quit location was unsafe, you have been teleported to the world's spawnpoint. */
UNSAFE_QUIT_LOCATION("unsafe_spawn"),
/** You're not logged in! */
NOT_LOGGED_IN("not_logged_in"),
@@ -179,9 +176,6 @@ public enum MessageKey {
/** Recovery email sent successfully! Please check your email inbox! */
RECOVERY_EMAIL_SENT_MESSAGE("email_send"),
/** A recovery email was already sent! You can discard it and send a new one using the command below: */
RECOVERY_EMAIL_ALREADY_SENT_MESSAGE("email_exists"),
/** Your country is banned from this server! */
COUNTRY_BANNED_ERROR("country_banned"),
@@ -227,7 +221,10 @@ public enum MessageKey {
/** The recovery code is not correct! You have %count tries remaining. */
INCORRECT_RECOVERY_CODE("recovery_code_incorrect", "%count"),
/** You have exceeded the maximum number of attempts to enter the recovery code. Use "/email recovery [email]" to generate a new one. */
/**
* You have exceeded the maximum number of attempts to enter the recovery code.
* Use "/email recovery [email]" to generate a new one.
*/
RECOVERY_TRIES_EXCEEDED("recovery_tries_exceeded"),
/** Recovery code entered correctly! */
@@ -9,6 +9,7 @@ import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
import fr.xephi.authme.mail.EmailService;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PlayerPermission;
@@ -64,6 +65,9 @@ public class AsynchronousLogin implements AsynchronousProcess {
@Inject
private LimboService limboService;
@Inject
private EmailService emailService;
AsynchronousLogin() {
}
@@ -189,6 +193,8 @@ public class AsynchronousLogin implements AsynchronousProcess {
limboService.muteMessageTask(player);
service.send(player, MessageKey.USAGE_CAPTCHA,
captchaManager.getCaptchaCodeOrGenerateNew(player.getName()));
} else if (emailService.hasAllInformation()) {
service.send(player, MessageKey.FORGOT_PASSWORD_MESSAGE);
}
}
}
@@ -262,11 +268,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
}
private void displayOtherAccounts(List<String> auths, Player player) {
if (!service.getProperty(RestrictionSettings.DISPLAY_OTHER_ACCOUNTS)) {
return;
}
if (auths.size() <= 1) {
if (!service.getProperty(RestrictionSettings.DISPLAY_OTHER_ACCOUNTS) || auths.size() <= 1) {
return;
}