mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-25 18:17:34 +01:00
#432 Add field injection to AccountsCommand
This commit is contained in:
parent
02079f1f5c
commit
5963628fa6
@ -256,7 +256,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
initializer.register(newSettings);
|
initializer.register(newSettings);
|
||||||
initializer.register(messages);
|
initializer.register(messages);
|
||||||
initializer.register(DataSource.class, database);
|
initializer.register(DataSource.class, database);
|
||||||
initializer.provide(BaseCommands.class, CommandInitializer.buildCommands());
|
initializer.provide(BaseCommands.class, CommandInitializer.buildCommands(initializer));
|
||||||
|
|
||||||
// Some statically injected things
|
// Some statically injected things
|
||||||
initializer.register(PlayerCache.class, PlayerCache.getInstance());
|
initializer.register(PlayerCache.class, PlayerCache.getInstance());
|
||||||
|
@ -33,6 +33,7 @@ import fr.xephi.authme.command.executable.login.LoginCommand;
|
|||||||
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
import fr.xephi.authme.command.executable.logout.LogoutCommand;
|
||||||
import fr.xephi.authme.command.executable.register.RegisterCommand;
|
import fr.xephi.authme.command.executable.register.RegisterCommand;
|
||||||
import fr.xephi.authme.command.executable.unregister.UnregisterCommand;
|
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.AdminPermission;
|
||||||
import fr.xephi.authme.permission.PlayerPermission;
|
import fr.xephi.authme.permission.PlayerPermission;
|
||||||
|
|
||||||
@ -53,13 +54,13 @@ public final class CommandInitializer {
|
|||||||
// Helper class
|
// Helper class
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<CommandDescription> buildCommands() {
|
public static Set<CommandDescription> buildCommands(AuthMeServiceInitializer initializer) {
|
||||||
// Register the base AuthMe Reloaded command
|
// Register the base AuthMe Reloaded command
|
||||||
final CommandDescription AUTHME_BASE = CommandDescription.builder()
|
final CommandDescription AUTHME_BASE = CommandDescription.builder()
|
||||||
.labels("authme")
|
.labels("authme")
|
||||||
.description("Main command")
|
.description("Main command")
|
||||||
.detailedDescription("The main AuthMeReloaded command. The root for all admin commands.")
|
.detailedDescription("The main AuthMeReloaded command. The root for all admin commands.")
|
||||||
.executableCommand(new AuthMeCommand())
|
.executableCommand(initializer.newInstance(AuthMeCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the register command
|
// Register the register command
|
||||||
@ -71,7 +72,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("player", "Player name", false)
|
.withArgument("player", "Player name", false)
|
||||||
.withArgument("password", "Password", false)
|
.withArgument("password", "Password", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.REGISTER)
|
.permissions(OP_ONLY, AdminPermission.REGISTER)
|
||||||
.executableCommand(new RegisterAdminCommand())
|
.executableCommand(initializer.newInstance(RegisterAdminCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the unregister command
|
// Register the unregister command
|
||||||
@ -82,7 +83,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Unregister the specified player.")
|
.detailedDescription("Unregister the specified player.")
|
||||||
.withArgument("player", "Player name", false)
|
.withArgument("player", "Player name", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.UNREGISTER)
|
.permissions(OP_ONLY, AdminPermission.UNREGISTER)
|
||||||
.executableCommand(new UnregisterAdminCommand())
|
.executableCommand(initializer.newInstance(UnregisterAdminCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the forcelogin command
|
// Register the forcelogin command
|
||||||
@ -93,7 +94,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Enforce the specified player to login.")
|
.detailedDescription("Enforce the specified player to login.")
|
||||||
.withArgument("player", "Online player name", true)
|
.withArgument("player", "Online player name", true)
|
||||||
.permissions(OP_ONLY, AdminPermission.FORCE_LOGIN)
|
.permissions(OP_ONLY, AdminPermission.FORCE_LOGIN)
|
||||||
.executableCommand(new ForceLoginCommand())
|
.executableCommand(initializer.newInstance(ForceLoginCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the changepassword command
|
// Register the changepassword command
|
||||||
@ -105,7 +106,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("player", "Player name", false)
|
.withArgument("player", "Player name", false)
|
||||||
.withArgument("pwd", "New password", false)
|
.withArgument("pwd", "New password", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.CHANGE_PASSWORD)
|
.permissions(OP_ONLY, AdminPermission.CHANGE_PASSWORD)
|
||||||
.executableCommand(new ChangePasswordAdminCommand())
|
.executableCommand(initializer.newInstance(ChangePasswordAdminCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the last login command
|
// Register the last login command
|
||||||
@ -116,7 +117,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("View the date of the specified players last login.")
|
.detailedDescription("View the date of the specified players last login.")
|
||||||
.withArgument("player", "Player name", true)
|
.withArgument("player", "Player name", true)
|
||||||
.permissions(OP_ONLY, AdminPermission.LAST_LOGIN)
|
.permissions(OP_ONLY, AdminPermission.LAST_LOGIN)
|
||||||
.executableCommand(new LastLoginCommand())
|
.executableCommand(initializer.newInstance(LastLoginCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the accounts command
|
// Register the accounts command
|
||||||
@ -127,7 +128,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Display all accounts of a player by his player name or IP.")
|
.detailedDescription("Display all accounts of a player by his player name or IP.")
|
||||||
.withArgument("player", "Player name or IP", true)
|
.withArgument("player", "Player name or IP", true)
|
||||||
.permissions(OP_ONLY, AdminPermission.ACCOUNTS)
|
.permissions(OP_ONLY, AdminPermission.ACCOUNTS)
|
||||||
.executableCommand(new AccountsCommand())
|
.executableCommand(initializer.newInstance(AccountsCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the getemail command
|
// Register the getemail command
|
||||||
@ -138,7 +139,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Display the email address of the specified player if set.")
|
.detailedDescription("Display the email address of the specified player if set.")
|
||||||
.withArgument("player", "Player name", true)
|
.withArgument("player", "Player name", true)
|
||||||
.permissions(OP_ONLY, AdminPermission.GET_EMAIL)
|
.permissions(OP_ONLY, AdminPermission.GET_EMAIL)
|
||||||
.executableCommand(new GetEmailCommand())
|
.executableCommand(initializer.newInstance(GetEmailCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the setemail command
|
// Register the setemail command
|
||||||
@ -150,7 +151,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("player", "Player name", false)
|
.withArgument("player", "Player name", false)
|
||||||
.withArgument("email", "Player email", false)
|
.withArgument("email", "Player email", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.CHANGE_EMAIL)
|
.permissions(OP_ONLY, AdminPermission.CHANGE_EMAIL)
|
||||||
.executableCommand(new SetEmailCommand())
|
.executableCommand(initializer.newInstance(SetEmailCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the getip command
|
// Register the getip command
|
||||||
@ -161,7 +162,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Get the IP address of the specified online player.")
|
.detailedDescription("Get the IP address of the specified online player.")
|
||||||
.withArgument("player", "Player name", false)
|
.withArgument("player", "Player name", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.GET_IP)
|
.permissions(OP_ONLY, AdminPermission.GET_IP)
|
||||||
.executableCommand(new GetIpCommand())
|
.executableCommand(initializer.newInstance(GetIpCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the spawn command
|
// Register the spawn command
|
||||||
@ -171,7 +172,7 @@ public final class CommandInitializer {
|
|||||||
.description("Teleport to spawn")
|
.description("Teleport to spawn")
|
||||||
.detailedDescription("Teleport to the spawn.")
|
.detailedDescription("Teleport to the spawn.")
|
||||||
.permissions(OP_ONLY, AdminPermission.SPAWN)
|
.permissions(OP_ONLY, AdminPermission.SPAWN)
|
||||||
.executableCommand(new SpawnCommand())
|
.executableCommand(initializer.newInstance(SpawnCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the setspawn command
|
// Register the setspawn command
|
||||||
@ -181,7 +182,7 @@ public final class CommandInitializer {
|
|||||||
.description("Change the spawn")
|
.description("Change the spawn")
|
||||||
.detailedDescription("Change the player's spawn to your current position.")
|
.detailedDescription("Change the player's spawn to your current position.")
|
||||||
.permissions(OP_ONLY, AdminPermission.SET_SPAWN)
|
.permissions(OP_ONLY, AdminPermission.SET_SPAWN)
|
||||||
.executableCommand(new SetSpawnCommand())
|
.executableCommand(initializer.newInstance(SetSpawnCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the firstspawn command
|
// Register the firstspawn command
|
||||||
@ -191,7 +192,7 @@ public final class CommandInitializer {
|
|||||||
.description("Teleport to first spawn")
|
.description("Teleport to first spawn")
|
||||||
.detailedDescription("Teleport to the first spawn.")
|
.detailedDescription("Teleport to the first spawn.")
|
||||||
.permissions(OP_ONLY, AdminPermission.FIRST_SPAWN)
|
.permissions(OP_ONLY, AdminPermission.FIRST_SPAWN)
|
||||||
.executableCommand(new FirstSpawnCommand())
|
.executableCommand(initializer.newInstance(FirstSpawnCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the setfirstspawn command
|
// Register the setfirstspawn command
|
||||||
@ -201,7 +202,7 @@ public final class CommandInitializer {
|
|||||||
.description("Change the first spawn")
|
.description("Change the first spawn")
|
||||||
.detailedDescription("Change the first player's spawn to your current position.")
|
.detailedDescription("Change the first player's spawn to your current position.")
|
||||||
.permissions(OP_ONLY, AdminPermission.SET_FIRST_SPAWN)
|
.permissions(OP_ONLY, AdminPermission.SET_FIRST_SPAWN)
|
||||||
.executableCommand(new SetFirstSpawnCommand())
|
.executableCommand(initializer.newInstance(SetFirstSpawnCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the purge command
|
// Register the purge command
|
||||||
@ -212,7 +213,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Purge old AuthMeReloaded data longer than the specified amount of days ago.")
|
.detailedDescription("Purge old AuthMeReloaded data longer than the specified amount of days ago.")
|
||||||
.withArgument("days", "Number of days", false)
|
.withArgument("days", "Number of days", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.PURGE)
|
.permissions(OP_ONLY, AdminPermission.PURGE)
|
||||||
.executableCommand(new PurgeCommand())
|
.executableCommand(initializer.newInstance(PurgeCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the purgelastposition command
|
// Register the purgelastposition command
|
||||||
@ -224,7 +225,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Purge the last know position of the specified player or all of them.")
|
.detailedDescription("Purge the last know position of the specified player or all of them.")
|
||||||
.withArgument("player/*", "Player name or * for all players", false)
|
.withArgument("player/*", "Player name or * for all players", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION)
|
.permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION)
|
||||||
.executableCommand(new PurgeLastPositionCommand())
|
.executableCommand(initializer.newInstance(PurgeLastPositionCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the purgebannedplayers command
|
// Register the purgebannedplayers command
|
||||||
@ -234,7 +235,7 @@ public final class CommandInitializer {
|
|||||||
.description("Purge banned players data")
|
.description("Purge banned players data")
|
||||||
.detailedDescription("Purge all AuthMeReloaded data for banned players.")
|
.detailedDescription("Purge all AuthMeReloaded data for banned players.")
|
||||||
.permissions(OP_ONLY, AdminPermission.PURGE_BANNED_PLAYERS)
|
.permissions(OP_ONLY, AdminPermission.PURGE_BANNED_PLAYERS)
|
||||||
.executableCommand(new PurgeBannedPlayersCommand())
|
.executableCommand(initializer.newInstance(PurgeBannedPlayersCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the switchantibot command
|
// Register the switchantibot command
|
||||||
@ -245,7 +246,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Switch or toggle the AntiBot mode to the specified state.")
|
.detailedDescription("Switch or toggle the AntiBot mode to the specified state.")
|
||||||
.withArgument("mode", "ON / OFF", true)
|
.withArgument("mode", "ON / OFF", true)
|
||||||
.permissions(OP_ONLY, AdminPermission.SWITCH_ANTIBOT)
|
.permissions(OP_ONLY, AdminPermission.SWITCH_ANTIBOT)
|
||||||
.executableCommand(new SwitchAntiBotCommand())
|
.executableCommand(initializer.newInstance(SwitchAntiBotCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the reload command
|
// Register the reload command
|
||||||
@ -255,7 +256,7 @@ public final class CommandInitializer {
|
|||||||
.description("Reload plugin")
|
.description("Reload plugin")
|
||||||
.detailedDescription("Reload the AuthMeReloaded plugin.")
|
.detailedDescription("Reload the AuthMeReloaded plugin.")
|
||||||
.permissions(OP_ONLY, AdminPermission.RELOAD)
|
.permissions(OP_ONLY, AdminPermission.RELOAD)
|
||||||
.executableCommand(new ReloadCommand())
|
.executableCommand(initializer.newInstance(ReloadCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the version command
|
// Register the version command
|
||||||
@ -265,7 +266,7 @@ public final class CommandInitializer {
|
|||||||
.description("Version info")
|
.description("Version info")
|
||||||
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, the "
|
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, the "
|
||||||
+ "developers, contributors, and license.")
|
+ "developers, contributors, and license.")
|
||||||
.executableCommand(new VersionCommand())
|
.executableCommand(initializer.newInstance(VersionCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
CommandDescription.builder()
|
CommandDescription.builder()
|
||||||
@ -276,7 +277,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " +
|
.withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " +
|
||||||
"royalauth / vauth / sqlitetosql", false)
|
"royalauth / vauth / sqlitetosql", false)
|
||||||
.permissions(OP_ONLY, AdminPermission.CONVERTER)
|
.permissions(OP_ONLY, AdminPermission.CONVERTER)
|
||||||
.executableCommand(new ConverterCommand())
|
.executableCommand(initializer.newInstance(ConverterCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the base login command
|
// Register the base login command
|
||||||
@ -287,7 +288,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Command to log in using AuthMeReloaded.")
|
.detailedDescription("Command to log in using AuthMeReloaded.")
|
||||||
.withArgument("password", "Login password", false)
|
.withArgument("password", "Login password", false)
|
||||||
.permissions(ALLOWED, PlayerPermission.LOGIN)
|
.permissions(ALLOWED, PlayerPermission.LOGIN)
|
||||||
.executableCommand(new LoginCommand())
|
.executableCommand(initializer.newInstance(LoginCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the base logout command
|
// Register the base logout command
|
||||||
@ -297,7 +298,7 @@ public final class CommandInitializer {
|
|||||||
.description("Logout command")
|
.description("Logout command")
|
||||||
.detailedDescription("Command to logout using AuthMeReloaded.")
|
.detailedDescription("Command to logout using AuthMeReloaded.")
|
||||||
.permissions(ALLOWED, PlayerPermission.LOGOUT)
|
.permissions(ALLOWED, PlayerPermission.LOGOUT)
|
||||||
.executableCommand(new LogoutCommand())
|
.executableCommand(initializer.newInstance(LogoutCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the base register command
|
// Register the base register command
|
||||||
@ -309,7 +310,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("password", "Password", true)
|
.withArgument("password", "Password", true)
|
||||||
.withArgument("verifyPassword", "Verify password", true)
|
.withArgument("verifyPassword", "Verify password", true)
|
||||||
.permissions(ALLOWED, PlayerPermission.REGISTER)
|
.permissions(ALLOWED, PlayerPermission.REGISTER)
|
||||||
.executableCommand(new RegisterCommand())
|
.executableCommand(initializer.newInstance(RegisterCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the base unregister command
|
// Register the base unregister command
|
||||||
@ -320,7 +321,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Command to unregister using AuthMeReloaded.")
|
.detailedDescription("Command to unregister using AuthMeReloaded.")
|
||||||
.withArgument("password", "Password", false)
|
.withArgument("password", "Password", false)
|
||||||
.permissions(ALLOWED, PlayerPermission.UNREGISTER)
|
.permissions(ALLOWED, PlayerPermission.UNREGISTER)
|
||||||
.executableCommand(new UnregisterCommand())
|
.executableCommand(initializer.newInstance(UnregisterCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the base changepassword command
|
// Register the base changepassword command
|
||||||
@ -332,7 +333,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("oldPassword", "Old Password", false)
|
.withArgument("oldPassword", "Old Password", false)
|
||||||
.withArgument("newPassword", "New Password.", false)
|
.withArgument("newPassword", "New Password.", false)
|
||||||
.permissions(ALLOWED, PlayerPermission.CHANGE_PASSWORD)
|
.permissions(ALLOWED, PlayerPermission.CHANGE_PASSWORD)
|
||||||
.executableCommand(new ChangePasswordCommand())
|
.executableCommand(initializer.newInstance(ChangePasswordCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the base Email command
|
// Register the base Email command
|
||||||
@ -341,7 +342,7 @@ public final class CommandInitializer {
|
|||||||
.labels("email", "mail")
|
.labels("email", "mail")
|
||||||
.description("Email command")
|
.description("Email command")
|
||||||
.detailedDescription("The AuthMeReloaded Email command base.")
|
.detailedDescription("The AuthMeReloaded Email command base.")
|
||||||
.executableCommand(new EmailBaseCommand())
|
.executableCommand(initializer.newInstance(EmailBaseCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the add command
|
// Register the add command
|
||||||
@ -353,7 +354,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("email", "Email address", false)
|
.withArgument("email", "Email address", false)
|
||||||
.withArgument("verifyEmail", "Email address verification", false)
|
.withArgument("verifyEmail", "Email address verification", false)
|
||||||
.permissions(ALLOWED, PlayerPermission.ADD_EMAIL)
|
.permissions(ALLOWED, PlayerPermission.ADD_EMAIL)
|
||||||
.executableCommand(new AddEmailCommand())
|
.executableCommand(initializer.newInstance(AddEmailCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the change command
|
// Register the change command
|
||||||
@ -365,7 +366,7 @@ public final class CommandInitializer {
|
|||||||
.withArgument("oldEmail", "Old email address", false)
|
.withArgument("oldEmail", "Old email address", false)
|
||||||
.withArgument("newEmail", "New email address", false)
|
.withArgument("newEmail", "New email address", false)
|
||||||
.permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL)
|
.permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL)
|
||||||
.executableCommand(new ChangeEmailCommand())
|
.executableCommand(initializer.newInstance(ChangeEmailCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the recover command
|
// Register the recover command
|
||||||
@ -377,7 +378,7 @@ public final class CommandInitializer {
|
|||||||
"a new password.")
|
"a new password.")
|
||||||
.withArgument("email", "Email address", false)
|
.withArgument("email", "Email address", false)
|
||||||
.permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL)
|
.permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL)
|
||||||
.executableCommand(new RecoverEmailCommand())
|
.executableCommand(initializer.newInstance(RecoverEmailCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register the base captcha command
|
// Register the base captcha command
|
||||||
@ -388,7 +389,7 @@ public final class CommandInitializer {
|
|||||||
.detailedDescription("Captcha command for AuthMeReloaded.")
|
.detailedDescription("Captcha command for AuthMeReloaded.")
|
||||||
.withArgument("captcha", "The Captcha", false)
|
.withArgument("captcha", "The Captcha", false)
|
||||||
.permissions(ALLOWED, PlayerPermission.CAPTCHA)
|
.permissions(ALLOWED, PlayerPermission.CAPTCHA)
|
||||||
.executableCommand(new CaptchaCommand())
|
.executableCommand(initializer.newInstance(CaptchaCommand.class))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Set<CommandDescription> baseCommands = ImmutableSet.of(
|
Set<CommandDescription> baseCommands = ImmutableSet.of(
|
||||||
@ -401,7 +402,7 @@ public final class CommandInitializer {
|
|||||||
EMAIL_BASE,
|
EMAIL_BASE,
|
||||||
CAPTCHA_BASE);
|
CAPTCHA_BASE);
|
||||||
|
|
||||||
setHelpOnAllBases(baseCommands);
|
setHelpOnAllBases(baseCommands, initializer);
|
||||||
return baseCommands;
|
return baseCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,9 +410,11 @@ public final class CommandInitializer {
|
|||||||
* Set the help command on all base commands, e.g. to register /authme help or /register help.
|
* Set 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
|
||||||
|
* @param initializer The service initializer
|
||||||
*/
|
*/
|
||||||
private static void setHelpOnAllBases(Collection<CommandDescription> commands) {
|
private static void setHelpOnAllBases(Collection<CommandDescription> commands,
|
||||||
final HelpCommand helpCommandExecutable = new HelpCommand();
|
AuthMeServiceInitializer initializer) {
|
||||||
|
final HelpCommand helpCommandExecutable = initializer.newInstance(HelpCommand.class);
|
||||||
final List<String> helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
|
final List<String> helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
|
||||||
|
|
||||||
for (CommandDescription base : commands) {
|
for (CommandDescription base : commands) {
|
||||||
|
@ -3,10 +3,13 @@ package fr.xephi.authme.command.executable.authme;
|
|||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.command.ExecutableCommand;
|
import fr.xephi.authme.command.ExecutableCommand;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
|
import fr.xephi.authme.output.Messages;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,6 +17,11 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class AccountsCommand implements ExecutableCommand {
|
public class AccountsCommand implements ExecutableCommand {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private DataSource dataSource;
|
||||||
|
@Inject
|
||||||
|
private Messages messages;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||||
final CommandService commandService) {
|
final CommandService commandService) {
|
||||||
@ -24,15 +32,15 @@ public class AccountsCommand implements ExecutableCommand {
|
|||||||
commandService.runTaskAsynchronously(new Runnable() {
|
commandService.runTaskAsynchronously(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
|
PlayerAuth auth = dataSource.getAuth(playerName.toLowerCase());
|
||||||
if (auth == null) {
|
if (auth == null) {
|
||||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
messages.send(sender, MessageKey.UNKNOWN_USER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> accountList = commandService.getDataSource().getAllAuthsByIp(auth.getIp());
|
List<String> accountList = dataSource.getAllAuthsByIp(auth.getIp());
|
||||||
if (accountList.isEmpty()) {
|
if (accountList.isEmpty()) {
|
||||||
commandService.send(sender, MessageKey.USER_NOT_REGISTERED);
|
messages.send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||||
} else if (accountList.size() == 1) {
|
} else if (accountList.size() == 1) {
|
||||||
sender.sendMessage("[AuthMe] " + playerName + " is a single account player");
|
sender.sendMessage("[AuthMe] " + playerName + " is a single account player");
|
||||||
} else {
|
} else {
|
||||||
@ -44,7 +52,7 @@ public class AccountsCommand implements ExecutableCommand {
|
|||||||
commandService.runTaskAsynchronously(new Runnable() {
|
commandService.runTaskAsynchronously(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
List<String> accountList = commandService.getDataSource().getAllAuthsByIp(playerName);
|
List<String> accountList = dataSource.getAllAuthsByIp(playerName);
|
||||||
if (accountList.isEmpty()) {
|
if (accountList.isEmpty()) {
|
||||||
sender.sendMessage("[AuthMe] This IP does not exist in the database.");
|
sender.sendMessage("[AuthMe] This IP does not exist in the database.");
|
||||||
} else if (accountList.size() == 1) {
|
} else if (accountList.size() == 1) {
|
||||||
|
@ -97,6 +97,18 @@ public class AuthMeServiceInitializer {
|
|||||||
objects.put(annotation, value);
|
objects.put(annotation, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the given class and does <i>not</i> keep track of it afterwards,
|
||||||
|
* unlike {@link #get(Class)} (singleton scope).
|
||||||
|
*
|
||||||
|
* @param clazz the class to instantiate
|
||||||
|
* @param <T> the class' type
|
||||||
|
* @return new instance of class T
|
||||||
|
*/
|
||||||
|
public <T> T newInstance(Class<T> clazz) {
|
||||||
|
return instantiate(clazz, new HashSet<Class<?>>());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an instance of the given class or the value associated with an annotation,
|
* Returns an instance of the given class or the value associated with an annotation,
|
||||||
* by retrieving it or by instantiating it if not yet present.
|
* by retrieving it or by instantiating it if not yet present.
|
||||||
@ -120,7 +132,6 @@ public class AuthMeServiceInitializer {
|
|||||||
|
|
||||||
traversedClasses = new HashSet<>(traversedClasses);
|
traversedClasses = new HashSet<>(traversedClasses);
|
||||||
traversedClasses.add(clazz);
|
traversedClasses.add(clazz);
|
||||||
System.out.println(Strings.repeat(" ", traversedClasses.size() * 2) + "- Instantiating " + clazz);
|
|
||||||
return instantiate(clazz, traversedClasses);
|
return instantiate(clazz, traversedClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package fr.xephi.authme.command;
|
package fr.xephi.authme.command;
|
||||||
|
|
||||||
|
import fr.xephi.authme.initialization.AuthMeServiceInitializer;
|
||||||
import fr.xephi.authme.permission.AdminPermission;
|
import fr.xephi.authme.permission.AdminPermission;
|
||||||
import fr.xephi.authme.permission.PermissionNode;
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -21,6 +24,9 @@ import static org.hamcrest.Matchers.not;
|
|||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link CommandInitializer} to guarantee the integrity of the defined commands.
|
* Test for {@link CommandInitializer} to guarantee the integrity of the defined commands.
|
||||||
@ -37,7 +43,16 @@ public class CommandInitializerTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initializeCommandManager() {
|
public static void initializeCommandManager() {
|
||||||
commands = CommandInitializer.buildCommands();
|
AuthMeServiceInitializer initializer = mock(AuthMeServiceInitializer.class);
|
||||||
|
when(initializer.newInstance(any(Class.class))).thenAnswer(new Answer<Object>() {
|
||||||
|
@Override
|
||||||
|
public Object answer(InvocationOnMock invocation) {
|
||||||
|
Class<?> clazz = (Class<?>) invocation.getArguments()[0];
|
||||||
|
return mock(clazz);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
commands = CommandInitializer.buildCommands(initializer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -4,10 +4,14 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
|
import fr.xephi.authme.output.Messages;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -22,26 +26,23 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link AccountsCommand}.
|
* Test for {@link AccountsCommand}.
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class AccountsCommandTest {
|
public class AccountsCommandTest {
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
private AccountsCommand command;
|
private AccountsCommand command;
|
||||||
|
@Mock
|
||||||
private CommandSender sender;
|
private CommandSender sender;
|
||||||
|
@Mock
|
||||||
private CommandService service;
|
private CommandService service;
|
||||||
|
@Mock
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
@Mock
|
||||||
@Before
|
private Messages messages;
|
||||||
public void setUpMocks() {
|
|
||||||
command = new AccountsCommand();
|
|
||||||
sender = mock(CommandSender.class);
|
|
||||||
dataSource = mock(DataSource.class);
|
|
||||||
service = mock(CommandService.class);
|
|
||||||
when(service.getDataSource()).thenReturn(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetAccountsOfCurrentUser() {
|
public void shouldGetAccountsOfCurrentUser() {
|
||||||
@ -72,7 +73,7 @@ public class AccountsCommandTest {
|
|||||||
runInnerRunnable(service);
|
runInnerRunnable(service);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(service).send(sender, MessageKey.UNKNOWN_USER);
|
verify(messages).send(sender, MessageKey.UNKNOWN_USER);
|
||||||
verify(sender, never()).sendMessage(anyString());
|
verify(sender, never()).sendMessage(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +89,7 @@ public class AccountsCommandTest {
|
|||||||
runInnerRunnable(service);
|
runInnerRunnable(service);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(service).send(sender, MessageKey.USER_NOT_REGISTERED);
|
verify(messages).send(sender, MessageKey.USER_NOT_REGISTERED);
|
||||||
verify(sender, never()).sendMessage(anyString());
|
verify(sender, never()).sendMessage(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package commands;
|
|||||||
|
|
||||||
import fr.xephi.authme.command.CommandArgumentDescription;
|
import fr.xephi.authme.command.CommandArgumentDescription;
|
||||||
import fr.xephi.authme.command.CommandDescription;
|
import fr.xephi.authme.command.CommandDescription;
|
||||||
import fr.xephi.authme.command.CommandInitializer;
|
|
||||||
import fr.xephi.authme.command.CommandPermissions;
|
import fr.xephi.authme.command.CommandPermissions;
|
||||||
import fr.xephi.authme.command.CommandUtils;
|
import fr.xephi.authme.command.CommandUtils;
|
||||||
import fr.xephi.authme.permission.PermissionNode;
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
@ -13,6 +12,7 @@ import utils.ToolTask;
|
|||||||
import utils.ToolsConstants;
|
import utils.ToolsConstants;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -27,7 +27,8 @@ public class CommandPageCreater implements ToolTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Scanner scanner) {
|
public void execute(Scanner scanner) {
|
||||||
final Set<CommandDescription> baseCommands = CommandInitializer.buildCommands();
|
// TODO ljacqu 20160427: Fix initialization of commands
|
||||||
|
final Set<CommandDescription> baseCommands = new HashSet<>();//CommandInitializer.buildCommands();
|
||||||
NestedTagValue commandTags = new NestedTagValue();
|
NestedTagValue commandTags = new NestedTagValue();
|
||||||
addCommandsInfo(commandTags, baseCommands);
|
addCommandsInfo(commandTags, baseCommands);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user