diff --git a/src/main/java/fr/xephi/authme/command/CommandDescription.java b/src/main/java/fr/xephi/authme/command/CommandDescription.java
index 7ff0e7394..115d0f23d 100644
--- a/src/main/java/fr/xephi/authme/command/CommandDescription.java
+++ b/src/main/java/fr/xephi/authme/command/CommandDescription.java
@@ -13,7 +13,7 @@ import static java.util.Arrays.asList;
/**
* Command description – defines which labels ("names") will lead to a command and points to the
* {@link ExecutableCommand} implementation that executes the logic of the command.
- *
+ *
* CommandDescription instances are built hierarchically: they have one parent, or {@code null} for base commands
* (main commands such as {@code /authme}), and may have multiple children extending the mapping of the parent: e.g. if
* {@code /authme} has a child whose label is {@code "register"}, then {@code /authme register} is the command that
@@ -37,7 +37,7 @@ public class CommandDescription {
/**
* The executable command instance described by this object.
*/
- private ExecutableCommand executableCommand;
+ private Class extends ExecutableCommand> executableCommand;
/**
* The parent command.
*/
@@ -57,7 +57,7 @@ public class CommandDescription {
/**
* Private constructor. Use {@link CommandDescription#builder()} to create instances of this class.
- *
+ *
* Note for developers: Instances should be created with {@link CommandDescription#createInstance} to be properly
* registered in the command tree.
*/
@@ -67,21 +67,20 @@ public class CommandDescription {
/**
* Create an instance.
*
- * @param labels List of command labels.
- * @param description Command description.
- * @param detailedDescription Detailed comment description.
- * @param executableCommand The executable command, or null.
- * @param parent Parent command.
- * @param arguments Command arguments.
- * @param permission The permission node required to execute this command.
+ * @param labels command labels
+ * @param description description of the command
+ * @param detailedDescription detailed command description
+ * @param executableCommand class of the command implementation
+ * @param parent parent command
+ * @param arguments command arguments
+ * @param permission permission node required to execute this command
*
- * @return The created instance
+ * @return the created instance
* @see CommandDescription#builder()
*/
private static CommandDescription createInstance(List labels, String description,
- String detailedDescription, ExecutableCommand executableCommand,
- CommandDescription parent, List arguments,
- PermissionNode permission) {
+ String detailedDescription, Class extends ExecutableCommand> executableCommand, CommandDescription parent,
+ List arguments, PermissionNode permission) {
CommandDescription instance = new CommandDescription();
instance.labels = labels;
instance.description = description;
@@ -133,7 +132,7 @@ public class CommandDescription {
*
* @return The executable command object.
*/
- public ExecutableCommand getExecutableCommand() {
+ public Class extends ExecutableCommand> getExecutableCommand() {
return executableCommand;
}
@@ -219,7 +218,7 @@ public class CommandDescription {
private List labels;
private String description;
private String detailedDescription;
- private ExecutableCommand executableCommand;
+ private Class extends ExecutableCommand> executableCommand;
private CommandDescription parent;
private List arguments = new ArrayList<>();
private PermissionNode permission;
@@ -260,7 +259,7 @@ public class CommandDescription {
return this;
}
- public CommandBuilder executableCommand(ExecutableCommand executableCommand) {
+ public CommandBuilder executableCommand(Class extends ExecutableCommand> executableCommand) {
this.executableCommand = executableCommand;
return this;
}
diff --git a/src/main/java/fr/xephi/authme/command/CommandHandler.java b/src/main/java/fr/xephi/authme/command/CommandHandler.java
index 8f493acbd..0b76a8222 100644
--- a/src/main/java/fr/xephi/authme/command/CommandHandler.java
+++ b/src/main/java/fr/xephi/authme/command/CommandHandler.java
@@ -2,6 +2,7 @@ package fr.xephi.authme.command;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.help.HelpProvider;
+import fr.xephi.authme.initialization.AuthMeServiceInitializer;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
@@ -9,7 +10,10 @@ import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* The AuthMe command handler, responsible for mapping incoming commands to the correct {@link CommandDescription}
@@ -23,12 +27,23 @@ public class CommandHandler {
*/
private static final double SUGGEST_COMMAND_THRESHOLD = 0.75;
- @Inject
- private CommandService commandService;
+ private final CommandMapper commandMapper;
+ private final PermissionsManager permissionsManager;
+ private final HelpProvider helpProvider;
+
+ /**
+ * Map with ExecutableCommand children. The key is the type of the value.
+ */
+ private Map, ExecutableCommand> commands = new HashMap<>();
@Inject
- private PermissionsManager permissionsManager;
-
+ public CommandHandler(AuthMeServiceInitializer initializer, CommandMapper commandMapper,
+ PermissionsManager permissionsManager, HelpProvider helpProvider) {
+ this.commandMapper = commandMapper;
+ this.permissionsManager = permissionsManager;
+ this.helpProvider = helpProvider;
+ initializeCommands(initializer, commandMapper.getCommandClasses());
+ }
/**
* Map a command that was invoked to the proper {@link CommandDescription} or return a useful error
@@ -45,7 +60,7 @@ public class CommandHandler {
List parts = skipEmptyArguments(bukkitArgs);
parts.add(0, bukkitCommandLabel);
- FoundCommandResult result = commandService.mapPartsToCommand(sender, parts);
+ FoundCommandResult result = commandMapper.mapPartsToCommand(sender, parts);
handleCommandResult(sender, result);
return !FoundResultStatus.MISSING_BASE_COMMAND.equals(result.getResultStatus());
}
@@ -72,6 +87,18 @@ public class CommandHandler {
}
}
+ /**
+ * Initializes all required ExecutableCommand objects.
+ *
+ * @param commandClasses the classes to instantiate
+ */
+ private void initializeCommands(AuthMeServiceInitializer initializer,
+ Set> commandClasses) {
+ for (Class extends ExecutableCommand> clazz : commandClasses) {
+ commands.put(clazz, initializer.newInstance(clazz));
+ }
+ }
+
/**
* Execute the command for the given command sender.
*
@@ -79,7 +106,7 @@ public class CommandHandler {
* @param result The mapped result
*/
private void executeCommand(CommandSender sender, FoundCommandResult result) {
- ExecutableCommand executableCommand = result.getCommandDescription().getExecutableCommand();
+ ExecutableCommand executableCommand = commands.get(result.getCommandDescription().getExecutableCommand());
List arguments = result.getArguments();
executableCommand.executeCommand(sender, arguments);
}
@@ -129,7 +156,7 @@ public class CommandHandler {
// Show the command argument help
sender.sendMessage(ChatColor.DARK_RED + "Incorrect command arguments!");
- commandService.outputHelp(sender, result, HelpProvider.SHOW_ARGUMENTS);
+ helpProvider.outputHelp(sender, result, HelpProvider.SHOW_ARGUMENTS);
List labels = result.getLabels();
String childLabel = labels.size() >= 2 ? labels.get(1) : "";
diff --git a/src/main/java/fr/xephi/authme/command/CommandInitializer.java b/src/main/java/fr/xephi/authme/command/CommandInitializer.java
index 7f6b2e26d..ce02b9a8d 100644
--- a/src/main/java/fr/xephi/authme/command/CommandInitializer.java
+++ b/src/main/java/fr/xephi/authme/command/CommandInitializer.java
@@ -33,11 +33,9 @@ import fr.xephi.authme.command.executable.login.LoginCommand;
import fr.xephi.authme.command.executable.logout.LogoutCommand;
import fr.xephi.authme.command.executable.register.RegisterCommand;
import fr.xephi.authme.command.executable.unregister.UnregisterCommand;
-import fr.xephi.authme.initialization.AuthMeServiceInitializer;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PlayerPermission;
-import javax.inject.Inject;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -48,16 +46,17 @@ import java.util.Set;
*/
public class CommandInitializer {
- private AuthMeServiceInitializer initializer;
-
private Set commands;
- @Inject
- public CommandInitializer(AuthMeServiceInitializer initializer) {
- this.initializer = initializer;
+ public CommandInitializer() {
buildCommands();
}
+ /**
+ * Returns the description of all AuthMe commands.
+ *
+ * @return the command descriptions
+ */
public Set getCommands() {
return commands;
}
@@ -68,7 +67,7 @@ public class CommandInitializer {
.labels("authme")
.description("Main command")
.detailedDescription("The main AuthMeReloaded command. The root for all admin commands.")
- .executableCommand(initializer.newInstance(AuthMeCommand.class))
+ .executableCommand(AuthMeCommand.class)
.build();
// Register the register command
@@ -80,7 +79,7 @@ public class CommandInitializer {
.withArgument("player", "Player name", false)
.withArgument("password", "Password", false)
.permission(AdminPermission.REGISTER)
- .executableCommand(initializer.newInstance(RegisterAdminCommand.class))
+ .executableCommand(RegisterAdminCommand.class)
.build();
// Register the unregister command
@@ -91,7 +90,7 @@ public class CommandInitializer {
.detailedDescription("Unregister the specified player.")
.withArgument("player", "Player name", false)
.permission(AdminPermission.UNREGISTER)
- .executableCommand(initializer.newInstance(UnregisterAdminCommand.class))
+ .executableCommand(UnregisterAdminCommand.class)
.build();
// Register the forcelogin command
@@ -102,7 +101,7 @@ public class CommandInitializer {
.detailedDescription("Enforce the specified player to login.")
.withArgument("player", "Online player name", true)
.permission(AdminPermission.FORCE_LOGIN)
- .executableCommand(initializer.newInstance(ForceLoginCommand.class))
+ .executableCommand(ForceLoginCommand.class)
.build();
// Register the changepassword command
@@ -114,7 +113,7 @@ public class CommandInitializer {
.withArgument("player", "Player name", false)
.withArgument("pwd", "New password", false)
.permission(AdminPermission.CHANGE_PASSWORD)
- .executableCommand(initializer.newInstance(ChangePasswordAdminCommand.class))
+ .executableCommand(ChangePasswordAdminCommand.class)
.build();
// Register the last login command
@@ -125,7 +124,7 @@ public class CommandInitializer {
.detailedDescription("View the date of the specified players last login.")
.withArgument("player", "Player name", true)
.permission(AdminPermission.LAST_LOGIN)
- .executableCommand(initializer.newInstance(LastLoginCommand.class))
+ .executableCommand(LastLoginCommand.class)
.build();
// Register the accounts command
@@ -136,7 +135,7 @@ public class CommandInitializer {
.detailedDescription("Display all accounts of a player by his player name or IP.")
.withArgument("player", "Player name or IP", true)
.permission(AdminPermission.ACCOUNTS)
- .executableCommand(initializer.newInstance(AccountsCommand.class))
+ .executableCommand(AccountsCommand.class)
.build();
// Register the getemail command
@@ -147,7 +146,7 @@ public class CommandInitializer {
.detailedDescription("Display the email address of the specified player if set.")
.withArgument("player", "Player name", true)
.permission(AdminPermission.GET_EMAIL)
- .executableCommand(initializer.newInstance(GetEmailCommand.class))
+ .executableCommand(GetEmailCommand.class)
.build();
// Register the setemail command
@@ -159,7 +158,7 @@ public class CommandInitializer {
.withArgument("player", "Player name", false)
.withArgument("email", "Player email", false)
.permission(AdminPermission.CHANGE_EMAIL)
- .executableCommand(initializer.newInstance(SetEmailCommand.class))
+ .executableCommand(SetEmailCommand.class)
.build();
// Register the getip command
@@ -170,7 +169,7 @@ public class CommandInitializer {
.detailedDescription("Get the IP address of the specified online player.")
.withArgument("player", "Player name", false)
.permission(AdminPermission.GET_IP)
- .executableCommand(initializer.newInstance(GetIpCommand.class))
+ .executableCommand(GetIpCommand.class)
.build();
// Register the spawn command
@@ -180,7 +179,7 @@ public class CommandInitializer {
.description("Teleport to spawn")
.detailedDescription("Teleport to the spawn.")
.permission(AdminPermission.SPAWN)
- .executableCommand(initializer.newInstance(SpawnCommand.class))
+ .executableCommand(SpawnCommand.class)
.build();
// Register the setspawn command
@@ -190,7 +189,7 @@ public class CommandInitializer {
.description("Change the spawn")
.detailedDescription("Change the player's spawn to your current position.")
.permission(AdminPermission.SET_SPAWN)
- .executableCommand(initializer.newInstance(SetSpawnCommand.class))
+ .executableCommand(SetSpawnCommand.class)
.build();
// Register the firstspawn command
@@ -200,7 +199,7 @@ public class CommandInitializer {
.description("Teleport to first spawn")
.detailedDescription("Teleport to the first spawn.")
.permission(AdminPermission.FIRST_SPAWN)
- .executableCommand(initializer.newInstance(FirstSpawnCommand.class))
+ .executableCommand(FirstSpawnCommand.class)
.build();
// Register the setfirstspawn command
@@ -210,7 +209,7 @@ public class CommandInitializer {
.description("Change the first spawn")
.detailedDescription("Change the first player's spawn to your current position.")
.permission(AdminPermission.SET_FIRST_SPAWN)
- .executableCommand(initializer.newInstance(SetFirstSpawnCommand.class))
+ .executableCommand(SetFirstSpawnCommand.class)
.build();
// Register the purge command
@@ -221,7 +220,7 @@ public class CommandInitializer {
.detailedDescription("Purge old AuthMeReloaded data longer than the specified amount of days ago.")
.withArgument("days", "Number of days", false)
.permission(AdminPermission.PURGE)
- .executableCommand(initializer.newInstance(PurgeCommand.class))
+ .executableCommand(PurgeCommand.class)
.build();
// Register the purgelastposition command
@@ -233,7 +232,7 @@ public class CommandInitializer {
.detailedDescription("Purge the last know position of the specified player or all of them.")
.withArgument("player/*", "Player name or * for all players", false)
.permission(AdminPermission.PURGE_LAST_POSITION)
- .executableCommand(initializer.newInstance(PurgeLastPositionCommand.class))
+ .executableCommand(PurgeLastPositionCommand.class)
.build();
// Register the purgebannedplayers command
@@ -243,7 +242,7 @@ public class CommandInitializer {
.description("Purge banned players data")
.detailedDescription("Purge all AuthMeReloaded data for banned players.")
.permission(AdminPermission.PURGE_BANNED_PLAYERS)
- .executableCommand(initializer.newInstance(PurgeBannedPlayersCommand.class))
+ .executableCommand(PurgeBannedPlayersCommand.class)
.build();
// Register the switchantibot command
@@ -254,7 +253,7 @@ public class CommandInitializer {
.detailedDescription("Switch or toggle the AntiBot mode to the specified state.")
.withArgument("mode", "ON / OFF", true)
.permission(AdminPermission.SWITCH_ANTIBOT)
- .executableCommand(initializer.newInstance(SwitchAntiBotCommand.class))
+ .executableCommand(SwitchAntiBotCommand.class)
.build();
// Register the reload command
@@ -264,7 +263,7 @@ public class CommandInitializer {
.description("Reload plugin")
.detailedDescription("Reload the AuthMeReloaded plugin.")
.permission(AdminPermission.RELOAD)
- .executableCommand(initializer.newInstance(ReloadCommand.class))
+ .executableCommand(ReloadCommand.class)
.build();
// Register the version command
@@ -274,7 +273,7 @@ public class CommandInitializer {
.description("Version info")
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, the "
+ "developers, contributors, and license.")
- .executableCommand(initializer.newInstance(VersionCommand.class))
+ .executableCommand(VersionCommand.class)
.build();
CommandDescription.builder()
@@ -285,7 +284,7 @@ public class CommandInitializer {
.withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " +
"royalauth / vauth / sqlitetosql", false)
.permission(AdminPermission.CONVERTER)
- .executableCommand(initializer.newInstance(ConverterCommand.class))
+ .executableCommand(ConverterCommand.class)
.build();
// Register the base login command
@@ -296,7 +295,7 @@ public class CommandInitializer {
.detailedDescription("Command to log in using AuthMeReloaded.")
.withArgument("password", "Login password", false)
.permission(PlayerPermission.LOGIN)
- .executableCommand(initializer.newInstance(LoginCommand.class))
+ .executableCommand(LoginCommand.class)
.build();
// Register the base logout command
@@ -306,7 +305,7 @@ public class CommandInitializer {
.description("Logout command")
.detailedDescription("Command to logout using AuthMeReloaded.")
.permission(PlayerPermission.LOGOUT)
- .executableCommand(initializer.newInstance(LogoutCommand.class))
+ .executableCommand(LogoutCommand.class)
.build();
// Register the base register command
@@ -318,7 +317,7 @@ public class CommandInitializer {
.withArgument("password", "Password", true)
.withArgument("verifyPassword", "Verify password", true)
.permission(PlayerPermission.REGISTER)
- .executableCommand(initializer.newInstance(RegisterCommand.class))
+ .executableCommand(RegisterCommand.class)
.build();
// Register the base unregister command
@@ -329,7 +328,7 @@ public class CommandInitializer {
.detailedDescription("Command to unregister using AuthMeReloaded.")
.withArgument("password", "Password", false)
.permission(PlayerPermission.UNREGISTER)
- .executableCommand(initializer.newInstance(UnregisterCommand.class))
+ .executableCommand(UnregisterCommand.class)
.build();
// Register the base changepassword command
@@ -341,7 +340,7 @@ public class CommandInitializer {
.withArgument("oldPassword", "Old Password", false)
.withArgument("newPassword", "New Password.", false)
.permission(PlayerPermission.CHANGE_PASSWORD)
- .executableCommand(initializer.newInstance(ChangePasswordCommand.class))
+ .executableCommand(ChangePasswordCommand.class)
.build();
// Register the base Email command
@@ -350,7 +349,7 @@ public class CommandInitializer {
.labels("email")
.description("Email command")
.detailedDescription("The AuthMeReloaded Email command base.")
- .executableCommand(initializer.newInstance(EmailBaseCommand.class))
+ .executableCommand(EmailBaseCommand.class)
.build();
// Register the add command
@@ -362,7 +361,7 @@ public class CommandInitializer {
.withArgument("email", "Email address", false)
.withArgument("verifyEmail", "Email address verification", false)
.permission(PlayerPermission.ADD_EMAIL)
- .executableCommand(initializer.newInstance(AddEmailCommand.class))
+ .executableCommand(AddEmailCommand.class)
.build();
// Register the change command
@@ -374,7 +373,7 @@ public class CommandInitializer {
.withArgument("oldEmail", "Old email address", false)
.withArgument("newEmail", "New email address", false)
.permission(PlayerPermission.CHANGE_EMAIL)
- .executableCommand(initializer.newInstance(ChangeEmailCommand.class))
+ .executableCommand(ChangeEmailCommand.class)
.build();
// Register the recover command
@@ -386,7 +385,7 @@ public class CommandInitializer {
"a new password.")
.withArgument("email", "Email address", false)
.permission(PlayerPermission.RECOVER_EMAIL)
- .executableCommand(initializer.newInstance(RecoverEmailCommand.class))
+ .executableCommand(RecoverEmailCommand.class)
.build();
// Register the base captcha command
@@ -397,7 +396,7 @@ public class CommandInitializer {
.detailedDescription("Captcha command for AuthMeReloaded.")
.withArgument("captcha", "The Captcha", false)
.permission(PlayerPermission.CAPTCHA)
- .executableCommand(initializer.newInstance(CaptchaCommand.class))
+ .executableCommand(CaptchaCommand.class)
.build();
Set baseCommands = ImmutableSet.of(
@@ -415,12 +414,11 @@ public class CommandInitializer {
}
/**
- * Set the help command on all base commands, e.g. to register /authme help or /register help.
+ * Sets the help command on all base commands, e.g. to register /authme help or /register help.
*
- * @param commands The list of base commands to register a help child command on
+ * @param commands the list of base commands to register a help child command on
*/
private void setHelpOnAllBases(Collection commands) {
- final HelpCommand helpCommandExecutable = initializer.newInstance(HelpCommand.class);
final List helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
for (CommandDescription base : commands) {
@@ -430,7 +428,7 @@ public class CommandInitializer {
.description("View help")
.detailedDescription("View detailed help for /" + base.getLabels().get(0) + " commands.")
.withArgument("query", "The command or query to view help for.", true)
- .executableCommand(helpCommandExecutable)
+ .executableCommand(HelpCommand.class)
.build();
}
}
diff --git a/src/main/java/fr/xephi/authme/command/CommandMapper.java b/src/main/java/fr/xephi/authme/command/CommandMapper.java
index 755cea0df..d0706c80b 100644
--- a/src/main/java/fr/xephi/authme/command/CommandMapper.java
+++ b/src/main/java/fr/xephi/authme/command/CommandMapper.java
@@ -8,6 +8,7 @@ import org.bukkit.command.CommandSender;
import javax.inject.Inject;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -69,6 +70,23 @@ public class CommandMapper {
return getCommandWithSmallestDifference(base, parts);
}
+ /**
+ * Return all {@link ExecutableCommand} classes referenced in {@link CommandDescription} objects.
+ *
+ * @return all classes
+ * @see CommandInitializer#getCommands
+ */
+ public Set> getCommandClasses() {
+ Set> classes = new HashSet<>(50);
+ for (CommandDescription command : baseCommands) {
+ classes.add(command.getExecutableCommand());
+ for (CommandDescription child : command.getChildren()) {
+ classes.add(child.getExecutableCommand());
+ }
+ }
+ return classes;
+ }
+
private FoundCommandResult getCommandWithSmallestDifference(CommandDescription base, List parts) {
// Return the base command with incorrect arg count error if we only have one part
if (parts.size() <= 1) {
@@ -141,7 +159,7 @@ public class CommandMapper {
private static FoundCommandResult transformResultForHelp(FoundCommandResult result) {
if (result.getCommandDescription() != null
- && HELP_COMMAND_CLASS.isAssignableFrom(result.getCommandDescription().getExecutableCommand().getClass())) {
+ && HELP_COMMAND_CLASS.isAssignableFrom(result.getCommandDescription().getExecutableCommand())) {
// For "/authme help register" we have labels = [authme, help] and arguments = [register]
// But for the help command we want labels = [authme, help] and arguments = [authme, register],
// so we can use the arguments as the labels to the command to show help for
diff --git a/src/main/java/fr/xephi/authme/command/CommandService.java b/src/main/java/fr/xephi/authme/command/CommandService.java
index acf150566..5efe79e80 100644
--- a/src/main/java/fr/xephi/authme/command/CommandService.java
+++ b/src/main/java/fr/xephi/authme/command/CommandService.java
@@ -1,6 +1,5 @@
package fr.xephi.authme.command;
-import fr.xephi.authme.command.help.HelpProvider;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.settings.NewSetting;
@@ -9,7 +8,6 @@ import fr.xephi.authme.util.ValidationService;
import org.bukkit.command.CommandSender;
import javax.inject.Inject;
-import java.util.List;
/**
* Service for implementations of {@link ExecutableCommand} to execute some common tasks.
@@ -20,10 +18,6 @@ public class CommandService {
@Inject
private Messages messages;
@Inject
- private HelpProvider helpProvider;
- @Inject
- private CommandMapper commandMapper;
- @Inject
private NewSetting settings;
@Inject
private ValidationService validationService;
@@ -49,31 +43,6 @@ public class CommandService {
messages.send(sender, messageKey, replacements);
}
- /**
- * Map command parts to a command description.
- *
- * @param sender The command sender issuing the request (for permission check), or null to skip permissions
- * @param commandParts The received command parts to map to a command
- * @return The computed mapping result
- */
- public FoundCommandResult mapPartsToCommand(CommandSender sender, List commandParts) {
- return commandMapper.mapPartsToCommand(sender, commandParts);
- }
-
- /**
- * Output the help for a given command.
- *
- * @param sender The sender to output the help to
- * @param result The result to output information about
- * @param options Output options, see {@link HelpProvider}
- */
- public void outputHelp(CommandSender sender, FoundCommandResult result, int options) {
- List lines = helpProvider.printHelp(sender, result, options);
- for (String line : lines) {
- sender.sendMessage(line);
- }
- }
-
/**
* Retrieve a message by its message key.
*
diff --git a/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java b/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java
index e912fb12d..2076bcbce 100644
--- a/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/HelpCommand.java
@@ -1,6 +1,6 @@
package fr.xephi.authme.command.executable;
-import fr.xephi.authme.command.CommandService;
+import fr.xephi.authme.command.CommandMapper;
import fr.xephi.authme.command.CommandUtils;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.FoundCommandResult;
@@ -18,14 +18,17 @@ import static fr.xephi.authme.command.FoundResultStatus.UNKNOWN_LABEL;
public class HelpCommand implements ExecutableCommand {
@Inject
- private CommandService commandService;
+ private CommandMapper commandMapper;
+
+ @Inject
+ private HelpProvider helpProvider;
// Convention: arguments is not the actual invoked arguments but the command that was invoked,
// e.g. "/authme help register" would typically be arguments = [register], but here we pass [authme, register]
@Override
public void executeCommand(CommandSender sender, List arguments) {
- FoundCommandResult result = commandService.mapPartsToCommand(sender, arguments);
+ FoundCommandResult result = commandMapper.mapPartsToCommand(sender, arguments);
FoundResultStatus resultStatus = result.getResultStatus();
if (MISSING_BASE_COMMAND.equals(resultStatus)) {
@@ -43,9 +46,9 @@ public class HelpCommand implements ExecutableCommand {
int mappedCommandLevel = result.getCommandDescription().getLabelCount();
if (mappedCommandLevel == 1) {
- commandService.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
+ helpProvider.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
} else {
- commandService.outputHelp(sender, result, HelpProvider.ALL_OPTIONS);
+ helpProvider.outputHelp(sender, result, HelpProvider.ALL_OPTIONS);
}
}
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java
index 37a709cf9..64a7241f2 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/SwitchAntiBotCommand.java
@@ -1,7 +1,7 @@
package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AntiBot;
-import fr.xephi.authme.command.CommandService;
+import fr.xephi.authme.command.CommandMapper;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.command.help.HelpProvider;
@@ -21,7 +21,10 @@ public class SwitchAntiBotCommand implements ExecutableCommand {
private AntiBot antiBot;
@Inject
- private CommandService commandService;
+ private CommandMapper commandMapper;
+
+ @Inject
+ private HelpProvider helpProvider;
@Override
public void executeCommand(final CommandSender sender, List arguments) {
@@ -41,8 +44,8 @@ public class SwitchAntiBotCommand implements ExecutableCommand {
sender.sendMessage("[AuthMe] AntiBot Manual Override: disabled!");
} else {
sender.sendMessage(ChatColor.DARK_RED + "Invalid AntiBot mode!");
- FoundCommandResult result = commandService.mapPartsToCommand(sender, Arrays.asList("authme", "antibot"));
- commandService.outputHelp(sender, result, HelpProvider.SHOW_ARGUMENTS);
+ FoundCommandResult result = commandMapper.mapPartsToCommand(sender, Arrays.asList("authme", "antibot"));
+ helpProvider.outputHelp(sender, result, HelpProvider.SHOW_ARGUMENTS);
sender.sendMessage(ChatColor.GOLD + "Detailed help: " + ChatColor.WHITE + "/authme help antibot");
}
}
diff --git a/src/main/java/fr/xephi/authme/command/executable/email/EmailBaseCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/EmailBaseCommand.java
index d75973f0d..0484e2189 100644
--- a/src/main/java/fr/xephi/authme/command/executable/email/EmailBaseCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/email/EmailBaseCommand.java
@@ -1,6 +1,6 @@
package fr.xephi.authme.command.executable.email;
-import fr.xephi.authme.command.CommandService;
+import fr.xephi.authme.command.CommandMapper;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.command.help.HelpProvider;
@@ -16,11 +16,14 @@ import java.util.List;
public class EmailBaseCommand implements ExecutableCommand {
@Inject
- private CommandService commandService;
+ private CommandMapper commandMapper;
+
+ @Inject
+ private HelpProvider helpProvider;
@Override
public void executeCommand(CommandSender sender, List arguments) {
- FoundCommandResult result = commandService.mapPartsToCommand(sender, Collections.singletonList("email"));
- commandService.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
+ FoundCommandResult result = commandMapper.mapPartsToCommand(sender, Collections.singletonList("email"));
+ helpProvider.outputHelp(sender, result, HelpProvider.SHOW_CHILDREN);
}
}
diff --git a/src/main/java/fr/xephi/authme/command/help/HelpProvider.java b/src/main/java/fr/xephi/authme/command/help/HelpProvider.java
index 7257b4d8b..4e07639df 100644
--- a/src/main/java/fr/xephi/authme/command/help/HelpProvider.java
+++ b/src/main/java/fr/xephi/authme/command/help/HelpProvider.java
@@ -53,7 +53,7 @@ public class HelpProvider implements SettingsDependent {
loadSettings(settings);
}
- public List printHelp(CommandSender sender, FoundCommandResult result, int options) {
+ private List printHelp(CommandSender sender, FoundCommandResult result, int options) {
if (result.getCommandDescription() == null) {
return singletonList(ChatColor.DARK_RED + "Failed to retrieve any help information!");
}
@@ -87,6 +87,20 @@ public class HelpProvider implements SettingsDependent {
return lines;
}
+ /**
+ * Output the help for a given command.
+ *
+ * @param sender The sender to output the help to
+ * @param result The result to output information about
+ * @param options Output options, see {@link HelpProvider}
+ */
+ public void outputHelp(CommandSender sender, FoundCommandResult result, int options) {
+ List lines = printHelp(sender, result, options);
+ for (String line : lines) {
+ sender.sendMessage(line);
+ }
+ }
+
@Override
public void loadSettings(NewSetting settings) {
helpHeader = settings.getProperty(PluginSettings.HELP_HEADER);
diff --git a/src/test/java/fr/xephi/authme/command/CommandConsistencyTest.java b/src/test/java/fr/xephi/authme/command/CommandConsistencyTest.java
index bb297268c..287b398a2 100644
--- a/src/test/java/fr/xephi/authme/command/CommandConsistencyTest.java
+++ b/src/test/java/fr/xephi/authme/command/CommandConsistencyTest.java
@@ -1,13 +1,9 @@
package fr.xephi.authme.command;
-
-import fr.xephi.authme.initialization.AuthMeServiceInitializer;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
import java.util.ArrayList;
import java.util.Collection;
@@ -22,9 +18,6 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
/**
* Checks that the commands declared in plugin.yml correspond
@@ -59,14 +52,7 @@ public class CommandConsistencyTest {
*/
@SuppressWarnings("unchecked")
private static Collection> initializeCommands() {
- AuthMeServiceInitializer injector = mock(AuthMeServiceInitializer.class);
- given(injector.newInstance(any(Class.class))).willAnswer(new Answer