#306 Add command service and set up constructor dependency injection

(work in progress)
- Pass all dependencies via constructor
- Encapsulate command handling more (e.g. split CommandHandler with new CommandMapper)
- Add help command to all base commands at one central point

See AccountsCommand or HelpCommand for an example of the advantages - all necessary functions come from CommandService; objects aren't retrieved through a singleton getInstance() method anymore
This commit is contained in:
ljacqu
2015-12-23 14:54:45 +01:00
parent f785d9d357
commit 8ef1b2ae3e
14 changed files with 517 additions and 471 deletions
@@ -24,7 +24,7 @@ import static java.util.Collections.singletonList;
/**
* Help syntax generator for AuthMe commands.
*/
public final class HelpProvider {
public class HelpProvider {
// --- Bit flags ---
/** Set to <i>not</i> show the command. */
@@ -43,13 +43,22 @@ public final class HelpProvider {
/** Shortcut for setting all options apart from {@link HelpProvider#HIDE_COMMAND}. */
public static final int ALL_OPTIONS = ~HIDE_COMMAND;
private HelpProvider() {
private final PermissionsManager permissionsManager;
public HelpProvider(PermissionsManager permissionsManager) {
this.permissionsManager = permissionsManager;
}
public static List<String> printHelp(FoundCommandResult foundCommand, int options) {
return printHelp(foundCommand, null, null, options);
}
public List<String> printHelp(CommandSender sender, FoundCommandResult result, int options) {
// FIXME don't overload and pass to the static method
// FIXME remove the static methods altogether
return printHelp(result, sender, permissionsManager, options);
}
// sender and permissions manager may be null if SHOW_PERMISSIONS is not set
public static List<String> printHelp(FoundCommandResult foundCommand, CommandSender sender,
PermissionsManager permissionsManager, int options) {