@@ -28,6 +30,7 @@ public class NewAPI {
*
* @param plugin The AuthMe plugin instance
*/
+ @Inject
public NewAPI(AuthMe plugin) {
this.plugin = plugin;
}
diff --git a/src/main/java/fr/xephi/authme/command/CommandHandler.java b/src/main/java/fr/xephi/authme/command/CommandHandler.java
index 37c1a2a1..5f7b32af 100644
--- a/src/main/java/fr/xephi/authme/command/CommandHandler.java
+++ b/src/main/java/fr/xephi/authme/command/CommandHandler.java
@@ -1,14 +1,14 @@
package fr.xephi.authme.command;
-import java.util.ArrayList;
-import java.util.List;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.help.HelpProvider;
+import fr.xephi.authme.util.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
-import fr.xephi.authme.util.StringUtils;
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
/**
* The AuthMe command handler, responsible for mapping incoming commands to the correct {@link CommandDescription}
@@ -29,6 +29,7 @@ public class CommandHandler {
*
* @param commandService The CommandService instance
*/
+ @Inject
public CommandHandler(CommandService commandService) {
this.commandService = commandService;
}
diff --git a/src/main/java/fr/xephi/authme/command/CommandInitializer.java b/src/main/java/fr/xephi/authme/command/CommandInitializer.java
index 6635545f..14d72f4a 100644
--- a/src/main/java/fr/xephi/authme/command/CommandInitializer.java
+++ b/src/main/java/fr/xephi/authme/command/CommandInitializer.java
@@ -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.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;
@@ -53,13 +54,13 @@ public final class CommandInitializer {
// Helper class
}
- public static Set buildCommands() {
+ public static Set buildCommands(AuthMeServiceInitializer initializer) {
// Register the base AuthMe Reloaded command
final CommandDescription AUTHME_BASE = CommandDescription.builder()
.labels("authme")
.description("Main command")
.detailedDescription("The main AuthMeReloaded command. The root for all admin commands.")
- .executableCommand(new AuthMeCommand())
+ .executableCommand(initializer.newInstance(AuthMeCommand.class))
.build();
// Register the register command
@@ -71,7 +72,7 @@ public final class CommandInitializer {
.withArgument("player", "Player name", false)
.withArgument("password", "Password", false)
.permissions(OP_ONLY, AdminPermission.REGISTER)
- .executableCommand(new RegisterAdminCommand())
+ .executableCommand(initializer.newInstance(RegisterAdminCommand.class))
.build();
// Register the unregister command
@@ -82,7 +83,7 @@ public final class CommandInitializer {
.detailedDescription("Unregister the specified player.")
.withArgument("player", "Player name", false)
.permissions(OP_ONLY, AdminPermission.UNREGISTER)
- .executableCommand(new UnregisterAdminCommand())
+ .executableCommand(initializer.newInstance(UnregisterAdminCommand.class))
.build();
// Register the forcelogin command
@@ -93,7 +94,7 @@ public final class CommandInitializer {
.detailedDescription("Enforce the specified player to login.")
.withArgument("player", "Online player name", true)
.permissions(OP_ONLY, AdminPermission.FORCE_LOGIN)
- .executableCommand(new ForceLoginCommand())
+ .executableCommand(initializer.newInstance(ForceLoginCommand.class))
.build();
// Register the changepassword command
@@ -105,7 +106,7 @@ public final class CommandInitializer {
.withArgument("player", "Player name", false)
.withArgument("pwd", "New password", false)
.permissions(OP_ONLY, AdminPermission.CHANGE_PASSWORD)
- .executableCommand(new ChangePasswordAdminCommand())
+ .executableCommand(initializer.newInstance(ChangePasswordAdminCommand.class))
.build();
// Register the last login command
@@ -116,7 +117,7 @@ public final class CommandInitializer {
.detailedDescription("View the date of the specified players last login.")
.withArgument("player", "Player name", true)
.permissions(OP_ONLY, AdminPermission.LAST_LOGIN)
- .executableCommand(new LastLoginCommand())
+ .executableCommand(initializer.newInstance(LastLoginCommand.class))
.build();
// 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.")
.withArgument("player", "Player name or IP", true)
.permissions(OP_ONLY, AdminPermission.ACCOUNTS)
- .executableCommand(new AccountsCommand())
+ .executableCommand(initializer.newInstance(AccountsCommand.class))
.build();
// Register the getemail command
@@ -138,7 +139,7 @@ public final class CommandInitializer {
.detailedDescription("Display the email address of the specified player if set.")
.withArgument("player", "Player name", true)
.permissions(OP_ONLY, AdminPermission.GET_EMAIL)
- .executableCommand(new GetEmailCommand())
+ .executableCommand(initializer.newInstance(GetEmailCommand.class))
.build();
// Register the setemail command
@@ -150,7 +151,7 @@ public final class CommandInitializer {
.withArgument("player", "Player name", false)
.withArgument("email", "Player email", false)
.permissions(OP_ONLY, AdminPermission.CHANGE_EMAIL)
- .executableCommand(new SetEmailCommand())
+ .executableCommand(initializer.newInstance(SetEmailCommand.class))
.build();
// Register the getip command
@@ -161,7 +162,7 @@ public final class CommandInitializer {
.detailedDescription("Get the IP address of the specified online player.")
.withArgument("player", "Player name", false)
.permissions(OP_ONLY, AdminPermission.GET_IP)
- .executableCommand(new GetIpCommand())
+ .executableCommand(initializer.newInstance(GetIpCommand.class))
.build();
// Register the spawn command
@@ -171,7 +172,7 @@ public final class CommandInitializer {
.description("Teleport to spawn")
.detailedDescription("Teleport to the spawn.")
.permissions(OP_ONLY, AdminPermission.SPAWN)
- .executableCommand(new SpawnCommand())
+ .executableCommand(initializer.newInstance(SpawnCommand.class))
.build();
// Register the setspawn command
@@ -181,7 +182,7 @@ public final class CommandInitializer {
.description("Change the spawn")
.detailedDescription("Change the player's spawn to your current position.")
.permissions(OP_ONLY, AdminPermission.SET_SPAWN)
- .executableCommand(new SetSpawnCommand())
+ .executableCommand(initializer.newInstance(SetSpawnCommand.class))
.build();
// Register the firstspawn command
@@ -191,7 +192,7 @@ public final class CommandInitializer {
.description("Teleport to first spawn")
.detailedDescription("Teleport to the first spawn.")
.permissions(OP_ONLY, AdminPermission.FIRST_SPAWN)
- .executableCommand(new FirstSpawnCommand())
+ .executableCommand(initializer.newInstance(FirstSpawnCommand.class))
.build();
// Register the setfirstspawn command
@@ -201,7 +202,7 @@ public final class CommandInitializer {
.description("Change the first spawn")
.detailedDescription("Change the first player's spawn to your current position.")
.permissions(OP_ONLY, AdminPermission.SET_FIRST_SPAWN)
- .executableCommand(new SetFirstSpawnCommand())
+ .executableCommand(initializer.newInstance(SetFirstSpawnCommand.class))
.build();
// 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.")
.withArgument("days", "Number of days", false)
.permissions(OP_ONLY, AdminPermission.PURGE)
- .executableCommand(new PurgeCommand())
+ .executableCommand(initializer.newInstance(PurgeCommand.class))
.build();
// 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.")
.withArgument("player/*", "Player name or * for all players", false)
.permissions(OP_ONLY, AdminPermission.PURGE_LAST_POSITION)
- .executableCommand(new PurgeLastPositionCommand())
+ .executableCommand(initializer.newInstance(PurgeLastPositionCommand.class))
.build();
// Register the purgebannedplayers command
@@ -234,7 +235,7 @@ public final class CommandInitializer {
.description("Purge banned players data")
.detailedDescription("Purge all AuthMeReloaded data for banned players.")
.permissions(OP_ONLY, AdminPermission.PURGE_BANNED_PLAYERS)
- .executableCommand(new PurgeBannedPlayersCommand())
+ .executableCommand(initializer.newInstance(PurgeBannedPlayersCommand.class))
.build();
// Register the switchantibot command
@@ -245,7 +246,7 @@ public final class CommandInitializer {
.detailedDescription("Switch or toggle the AntiBot mode to the specified state.")
.withArgument("mode", "ON / OFF", true)
.permissions(OP_ONLY, AdminPermission.SWITCH_ANTIBOT)
- .executableCommand(new SwitchAntiBotCommand())
+ .executableCommand(initializer.newInstance(SwitchAntiBotCommand.class))
.build();
// Register the reload command
@@ -255,7 +256,7 @@ public final class CommandInitializer {
.description("Reload plugin")
.detailedDescription("Reload the AuthMeReloaded plugin.")
.permissions(OP_ONLY, AdminPermission.RELOAD)
- .executableCommand(new ReloadCommand())
+ .executableCommand(initializer.newInstance(ReloadCommand.class))
.build();
// Register the version command
@@ -265,7 +266,7 @@ public final class CommandInitializer {
.description("Version info")
.detailedDescription("Show detailed information about the installed AuthMeReloaded version, the "
+ "developers, contributors, and license.")
- .executableCommand(new VersionCommand())
+ .executableCommand(initializer.newInstance(VersionCommand.class))
.build();
CommandDescription.builder()
@@ -276,7 +277,7 @@ public final class CommandInitializer {
.withArgument("job", "Conversion job: xauth / crazylogin / rakamak / " +
"royalauth / vauth / sqlitetosql", false)
.permissions(OP_ONLY, AdminPermission.CONVERTER)
- .executableCommand(new ConverterCommand())
+ .executableCommand(initializer.newInstance(ConverterCommand.class))
.build();
// Register the base login command
@@ -287,7 +288,7 @@ public final class CommandInitializer {
.detailedDescription("Command to log in using AuthMeReloaded.")
.withArgument("password", "Login password", false)
.permissions(ALLOWED, PlayerPermission.LOGIN)
- .executableCommand(new LoginCommand())
+ .executableCommand(initializer.newInstance(LoginCommand.class))
.build();
// Register the base logout command
@@ -297,7 +298,7 @@ public final class CommandInitializer {
.description("Logout command")
.detailedDescription("Command to logout using AuthMeReloaded.")
.permissions(ALLOWED, PlayerPermission.LOGOUT)
- .executableCommand(new LogoutCommand())
+ .executableCommand(initializer.newInstance(LogoutCommand.class))
.build();
// Register the base register command
@@ -309,7 +310,7 @@ public final class CommandInitializer {
.withArgument("password", "Password", true)
.withArgument("verifyPassword", "Verify password", true)
.permissions(ALLOWED, PlayerPermission.REGISTER)
- .executableCommand(new RegisterCommand())
+ .executableCommand(initializer.newInstance(RegisterCommand.class))
.build();
// Register the base unregister command
@@ -320,7 +321,7 @@ public final class CommandInitializer {
.detailedDescription("Command to unregister using AuthMeReloaded.")
.withArgument("password", "Password", false)
.permissions(ALLOWED, PlayerPermission.UNREGISTER)
- .executableCommand(new UnregisterCommand())
+ .executableCommand(initializer.newInstance(UnregisterCommand.class))
.build();
// Register the base changepassword command
@@ -332,7 +333,7 @@ public final class CommandInitializer {
.withArgument("oldPassword", "Old Password", false)
.withArgument("newPassword", "New Password.", false)
.permissions(ALLOWED, PlayerPermission.CHANGE_PASSWORD)
- .executableCommand(new ChangePasswordCommand())
+ .executableCommand(initializer.newInstance(ChangePasswordCommand.class))
.build();
// Register the base Email command
@@ -341,7 +342,7 @@ public final class CommandInitializer {
.labels("email", "mail")
.description("Email command")
.detailedDescription("The AuthMeReloaded Email command base.")
- .executableCommand(new EmailBaseCommand())
+ .executableCommand(initializer.newInstance(EmailBaseCommand.class))
.build();
// Register the add command
@@ -353,7 +354,7 @@ public final class CommandInitializer {
.withArgument("email", "Email address", false)
.withArgument("verifyEmail", "Email address verification", false)
.permissions(ALLOWED, PlayerPermission.ADD_EMAIL)
- .executableCommand(new AddEmailCommand())
+ .executableCommand(initializer.newInstance(AddEmailCommand.class))
.build();
// Register the change command
@@ -365,7 +366,7 @@ public final class CommandInitializer {
.withArgument("oldEmail", "Old email address", false)
.withArgument("newEmail", "New email address", false)
.permissions(ALLOWED, PlayerPermission.CHANGE_EMAIL)
- .executableCommand(new ChangeEmailCommand())
+ .executableCommand(initializer.newInstance(ChangeEmailCommand.class))
.build();
// Register the recover command
@@ -377,7 +378,7 @@ public final class CommandInitializer {
"a new password.")
.withArgument("email", "Email address", false)
.permissions(ALLOWED, PlayerPermission.RECOVER_EMAIL)
- .executableCommand(new RecoverEmailCommand())
+ .executableCommand(initializer.newInstance(RecoverEmailCommand.class))
.build();
// Register the base captcha command
@@ -388,7 +389,7 @@ public final class CommandInitializer {
.detailedDescription("Captcha command for AuthMeReloaded.")
.withArgument("captcha", "The Captcha", false)
.permissions(ALLOWED, PlayerPermission.CAPTCHA)
- .executableCommand(new CaptchaCommand())
+ .executableCommand(initializer.newInstance(CaptchaCommand.class))
.build();
Set baseCommands = ImmutableSet.of(
@@ -401,7 +402,7 @@ public final class CommandInitializer {
EMAIL_BASE,
CAPTCHA_BASE);
- setHelpOnAllBases(baseCommands);
+ setHelpOnAllBases(baseCommands, initializer);
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.
*
* @param commands The list of base commands to register a help child command on
+ * @param initializer The service initializer
*/
- private static void setHelpOnAllBases(Collection commands) {
- final HelpCommand helpCommandExecutable = new HelpCommand();
+ private static void setHelpOnAllBases(Collection commands,
+ AuthMeServiceInitializer initializer) {
+ final HelpCommand helpCommandExecutable = initializer.newInstance(HelpCommand.class);
final List helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
for (CommandDescription base : commands) {
diff --git a/src/main/java/fr/xephi/authme/command/CommandMapper.java b/src/main/java/fr/xephi/authme/command/CommandMapper.java
index e43ee4bb..18473b28 100644
--- a/src/main/java/fr/xephi/authme/command/CommandMapper.java
+++ b/src/main/java/fr/xephi/authme/command/CommandMapper.java
@@ -1,11 +1,13 @@
package fr.xephi.authme.command;
import fr.xephi.authme.command.executable.HelpCommand;
+import fr.xephi.authme.initialization.BaseCommands;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.util.CollectionUtils;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -28,7 +30,8 @@ public class CommandMapper {
private final Set baseCommands;
private final PermissionsManager permissionsManager;
- public CommandMapper(Set baseCommands, PermissionsManager permissionsManager) {
+ @Inject
+ public CommandMapper(@BaseCommands Set baseCommands, PermissionsManager permissionsManager) {
this.baseCommands = baseCommands;
this.permissionsManager = permissionsManager;
}
diff --git a/src/main/java/fr/xephi/authme/command/CommandService.java b/src/main/java/fr/xephi/authme/command/CommandService.java
index 5c5abfcc..95ddb563 100644
--- a/src/main/java/fr/xephi/authme/command/CommandService.java
+++ b/src/main/java/fr/xephi/authme/command/CommandService.java
@@ -1,10 +1,7 @@
package fr.xephi.authme.command;
-import fr.xephi.authme.AntiBot;
import fr.xephi.authme.AuthMe;
-import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.help.HelpProvider;
-import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
@@ -19,6 +16,7 @@ import fr.xephi.authme.util.ValidationService;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import javax.inject.Inject;
import java.util.Collection;
import java.util.List;
@@ -28,39 +26,28 @@ import java.util.List;
*/
public class CommandService {
- private final AuthMe authMe;
- private final Messages messages;
- private final HelpProvider helpProvider;
- private final CommandMapper commandMapper;
- private final PasswordSecurity passwordSecurity;
- private final PermissionsManager permissionsManager;
- private final NewSetting settings;
- private final PluginHooks pluginHooks;
- private final SpawnLoader spawnLoader;
- private final AntiBot antiBot;
- private final ValidationService validationService;
- private final BukkitService bukkitService;
-
- /*
- * Constructor.
- */
- public CommandService(AuthMe authMe, CommandMapper commandMapper, HelpProvider helpProvider, Messages messages,
- PasswordSecurity passwordSecurity, PermissionsManager permissionsManager, NewSetting settings,
- PluginHooks pluginHooks, SpawnLoader spawnLoader, AntiBot antiBot,
- ValidationService validationService, BukkitService bukkitService) {
- this.authMe = authMe;
- this.messages = messages;
- this.helpProvider = helpProvider;
- this.commandMapper = commandMapper;
- this.passwordSecurity = passwordSecurity;
- this.permissionsManager = permissionsManager;
- this.settings = settings;
- this.pluginHooks = pluginHooks;
- this.spawnLoader = spawnLoader;
- this.antiBot = antiBot;
- this.validationService = validationService;
- this.bukkitService = bukkitService;
- }
+ @Inject
+ private AuthMe authMe;
+ @Inject
+ private Messages messages;
+ @Inject
+ private HelpProvider helpProvider;
+ @Inject
+ private CommandMapper commandMapper;
+ @Inject
+ private PasswordSecurity passwordSecurity;
+ @Inject
+ private PermissionsManager permissionsManager;
+ @Inject
+ private NewSetting settings;
+ @Inject
+ private PluginHooks pluginHooks;
+ @Inject
+ private SpawnLoader spawnLoader;
+ @Inject
+ private ValidationService validationService;
+ @Inject
+ private BukkitService bukkitService;
/**
* Send a message to a player.
@@ -103,15 +90,6 @@ public class CommandService {
authMe.getServer().getScheduler().runTaskAsynchronously(authMe, task);
}
- /**
- * Return the AuthMe data source.
- *
- * @return The used data source
- */
- public DataSource getDataSource() {
- return authMe.getDataSource();
- }
-
/**
* Return the AuthMe instance for further manipulation. Use only if other methods from
* the command service cannot be used.
@@ -122,15 +100,6 @@ public class CommandService {
return authMe;
}
- /**
- * Return the PasswordSecurity instance.
- *
- * @return The password security instance
- */
- public PasswordSecurity getPasswordSecurity() {
- return passwordSecurity;
- }
-
/**
* Output the help for a given command.
*
@@ -193,10 +162,6 @@ public class CommandService {
return settings;
}
- public PlayerCache getPlayerCache() {
- return PlayerCache.getInstance();
- }
-
public PluginHooks getPluginHooks() {
return pluginHooks;
}
@@ -205,10 +170,6 @@ public class CommandService {
return spawnLoader;
}
- public AntiBot getAntiBot() {
- return antiBot;
- }
-
/**
* Verifies whether a password is valid according to the plugin settings.
*
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java
index d3698cfd..ad5bf9b2 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/AccountsCommand.java
@@ -3,10 +3,13 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
+import fr.xephi.authme.output.Messages;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.List;
/**
@@ -14,6 +17,11 @@ import java.util.List;
*/
public class AccountsCommand implements ExecutableCommand {
+ @Inject
+ private DataSource dataSource;
+ @Inject
+ private Messages messages;
+
@Override
public void executeCommand(final CommandSender sender, List arguments,
final CommandService commandService) {
@@ -24,15 +32,15 @@ public class AccountsCommand implements ExecutableCommand {
commandService.runTaskAsynchronously(new Runnable() {
@Override
public void run() {
- PlayerAuth auth = commandService.getDataSource().getAuth(playerName.toLowerCase());
+ PlayerAuth auth = dataSource.getAuth(playerName.toLowerCase());
if (auth == null) {
- commandService.send(sender, MessageKey.UNKNOWN_USER);
+ messages.send(sender, MessageKey.UNKNOWN_USER);
return;
}
- List accountList = commandService.getDataSource().getAllAuthsByIp(auth.getIp());
+ List accountList = dataSource.getAllAuthsByIp(auth.getIp());
if (accountList.isEmpty()) {
- commandService.send(sender, MessageKey.USER_NOT_REGISTERED);
+ messages.send(sender, MessageKey.USER_NOT_REGISTERED);
} else if (accountList.size() == 1) {
sender.sendMessage("[AuthMe] " + playerName + " is a single account player");
} else {
@@ -44,7 +52,7 @@ public class AccountsCommand implements ExecutableCommand {
commandService.runTaskAsynchronously(new Runnable() {
@Override
public void run() {
- List accountList = commandService.getDataSource().getAllAuthsByIp(playerName);
+ List accountList = dataSource.getAllAuthsByIp(playerName);
if (accountList.isEmpty()) {
sender.sendMessage("[AuthMe] This IP does not exist in the database.");
} else if (accountList.size() == 1) {
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java
index 867443ed..f81ac07f 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/ChangePasswordAdminCommand.java
@@ -2,13 +2,16 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
+import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
+import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.List;
/**
@@ -16,6 +19,15 @@ import java.util.List;
*/
public class ChangePasswordAdminCommand implements ExecutableCommand {
+ @Inject
+ private PasswordSecurity passwordSecurity;
+
+ @Inject
+ private PlayerCache playerCache;
+
+ @Inject
+ private DataSource dataSource;
+
@Override
public void executeCommand(final CommandSender sender, List arguments,
final CommandService commandService) {
@@ -36,10 +48,9 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
@Override
public void run() {
- DataSource dataSource = commandService.getDataSource();
PlayerAuth auth = null;
- if (commandService.getPlayerCache().isAuthenticated(playerNameLowerCase)) {
- auth = commandService.getPlayerCache().getAuth(playerNameLowerCase);
+ if (playerCache.isAuthenticated(playerNameLowerCase)) {
+ auth = playerCache.getAuth(playerNameLowerCase);
} else if (dataSource.isAuthAvailable(playerNameLowerCase)) {
auth = dataSource.getAuth(playerNameLowerCase);
}
@@ -48,8 +59,7 @@ public class ChangePasswordAdminCommand implements ExecutableCommand {
return;
}
- HashedPassword hashedPassword = commandService.getPasswordSecurity()
- .computeHash(playerPass, playerNameLowerCase);
+ HashedPassword hashedPassword = passwordSecurity.computeHash(playerPass, playerNameLowerCase);
auth.setPassword(hashedPassword);
if (!dataSource.updatePassword(auth)) {
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java
index 53a3051c..ede9a424 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/GetEmailCommand.java
@@ -3,9 +3,11 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.List;
/**
@@ -13,11 +15,14 @@ import java.util.List;
*/
public class GetEmailCommand implements ExecutableCommand {
+ @Inject
+ private DataSource dataSource;
+
@Override
public void executeCommand(CommandSender sender, List arguments, CommandService commandService) {
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
- PlayerAuth auth = commandService.getDataSource().getAuth(playerName);
+ PlayerAuth auth = dataSource.getAuth(playerName);
if (auth == null) {
commandService.send(sender, MessageKey.UNKNOWN_USER);
} else {
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java
index 05fdab2b..4f0135a2 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/LastLoginCommand.java
@@ -3,9 +3,11 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.Date;
import java.util.List;
@@ -14,12 +16,15 @@ import java.util.List;
*/
public class LastLoginCommand implements ExecutableCommand {
+ @Inject
+ private DataSource dataSource;
+
@Override
public void executeCommand(CommandSender sender, List arguments, CommandService commandService) {
// Get the player
String playerName = (arguments.size() >= 1) ? arguments.get(0) : sender.getName();
- PlayerAuth auth = commandService.getDataSource().getAuth(playerName);
+ PlayerAuth auth = dataSource.getAuth(playerName);
if (auth == null) {
commandService.send(sender, MessageKey.USER_NOT_REGISTERED);
return;
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java
index 0ace9424..99535027 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeBannedPlayersCommand.java
@@ -3,10 +3,12 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.settings.properties.PurgeSettings;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@@ -16,6 +18,9 @@ import java.util.List;
*/
public class PurgeBannedPlayersCommand implements ExecutableCommand {
+ @Inject
+ private DataSource dataSource;
+
@Override
public void executeCommand(CommandSender sender, List arguments, CommandService commandService) {
// AuthMe plugin instance
@@ -23,12 +28,12 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
// Get the list of banned players
List bannedPlayers = new ArrayList<>();
- for (OfflinePlayer offlinePlayer : plugin.getServer().getBannedPlayers()) {
+ for (OfflinePlayer offlinePlayer : commandService.getBukkitService().getBannedPlayers()) {
bannedPlayers.add(offlinePlayer.getName().toLowerCase());
}
// Purge the banned players
- commandService.getDataSource().purgeBanned(bannedPlayers);
+ dataSource.purgeBanned(bannedPlayers);
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES)
&& commandService.getPluginHooks().isEssentialsAvailable())
plugin.dataManager.purgeEssentials(bannedPlayers);
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java
index 43e1daa5..51ca6df1 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeCommand.java
@@ -3,10 +3,12 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.settings.properties.PurgeSettings;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.Calendar;
import java.util.List;
@@ -18,6 +20,9 @@ public class PurgeCommand implements ExecutableCommand {
private static final int MINIMUM_LAST_SEEN_DAYS = 30;
+ @Inject
+ private DataSource dataSource;
+
@Override
public void executeCommand(CommandSender sender, List arguments, CommandService commandService) {
// Get the days parameter
@@ -45,7 +50,7 @@ public class PurgeCommand implements ExecutableCommand {
long until = calendar.getTimeInMillis();
// Purge the data, get the purged values
- List purged = commandService.getDataSource().autoPurgeDatabase(until);
+ List purged = dataSource.autoPurgeDatabase(until);
// Show a status message
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java
index 118f8460..7c88df86 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/PurgeLastPositionCommand.java
@@ -3,9 +3,11 @@ package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.List;
/**
@@ -13,26 +15,29 @@ import java.util.List;
*/
public class PurgeLastPositionCommand implements ExecutableCommand {
+ @Inject
+ private DataSource dataSource;
+
@Override
public void executeCommand(final CommandSender sender, List arguments, CommandService commandService) {
String playerName = arguments.isEmpty() ? sender.getName() : arguments.get(0);
if ("*".equals(playerName)) {
- for (PlayerAuth auth : commandService.getDataSource().getAllAuths()) {
+ for (PlayerAuth auth : dataSource.getAllAuths()) {
resetLastPosition(auth);
- commandService.getDataSource().updateQuitLoc(auth);
+ dataSource.updateQuitLoc(auth);
}
sender.sendMessage("All players last position locations are now reset");
} else {
// Get the user auth and make sure the user exists
- PlayerAuth auth = commandService.getDataSource().getAuth(playerName);
+ PlayerAuth auth = dataSource.getAuth(playerName);
if (auth == null) {
commandService.send(sender, MessageKey.UNKNOWN_USER);
return;
}
resetLastPosition(auth);
- commandService.getDataSource().updateQuitLoc(auth);
+ dataSource.updateQuitLoc(auth);
sender.sendMessage(playerName + "'s last position location is now reset");
}
}
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java
index 2c842aee..5ddd0b95 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java
@@ -1,22 +1,30 @@
package fr.xephi.authme.command.executable.authme;
-import java.util.List;
-
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
+import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.crypts.HashedPassword;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+import javax.inject.Inject;
+import java.util.List;
/**
* Admin command to register a user.
*/
public class RegisterAdminCommand implements ExecutableCommand {
+ @Inject
+ private PasswordSecurity passwordSecurity;
+
+ @Inject
+ private DataSource dataSource;
+
@Override
public void executeCommand(final CommandSender sender, List arguments,
final CommandService commandService) {
@@ -36,33 +44,31 @@ public class RegisterAdminCommand implements ExecutableCommand {
@Override
public void run() {
- if (commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
+ if (dataSource.isAuthAvailable(playerNameLowerCase)) {
commandService.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
return;
}
- HashedPassword hashedPassword = commandService.getPasswordSecurity()
- .computeHash(playerPass, playerNameLowerCase);
+ HashedPassword hashedPassword = passwordSecurity.computeHash(playerPass, playerNameLowerCase);
PlayerAuth auth = PlayerAuth.builder()
.name(playerNameLowerCase)
.realName(playerName)
.password(hashedPassword)
.build();
- if (!commandService.getDataSource().saveAuth(auth)) {
+ if (!dataSource.saveAuth(auth)) {
commandService.send(sender, MessageKey.ERROR);
return;
}
- commandService.getDataSource().setUnlogged(playerNameLowerCase);
+ dataSource.setUnlogged(playerNameLowerCase);
commandService.send(sender, MessageKey.REGISTER_SUCCESS);
ConsoleLogger.info(sender.getName() + " registered " + playerName);
- Player player = commandService.getPlayer(playerName);
+ final Player player = commandService.getPlayer(playerName);
if (player != null) {
- final Player p = player;
- p.getServer().getScheduler().scheduleSyncDelayedTask(commandService.getAuthMe(), new Runnable() {
+ commandService.getBukkitService().scheduleSyncDelayedTask(new Runnable() {
@Override
public void run() {
- p.kickPlayer("An admin just registered you, please log in again");
+ player.kickPlayer("An admin just registered you, please log in again");
}
});
}
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java
index 0e7bcf35..989c7210 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/SetEmailCommand.java
@@ -8,6 +8,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.List;
/**
@@ -15,6 +16,12 @@ import java.util.List;
*/
public class SetEmailCommand implements ExecutableCommand {
+ @Inject
+ private DataSource dataSource;
+
+ @Inject
+ private PlayerCache playerCache;
+
@Override
public void executeCommand(final CommandSender sender, List arguments,
final CommandService commandService) {
@@ -32,7 +39,6 @@ public class SetEmailCommand implements ExecutableCommand {
@Override
public void run() {
// Validate the user
- DataSource dataSource = commandService.getDataSource();
PlayerAuth auth = dataSource.getAuth(playerName);
if (auth == null) {
commandService.send(sender, MessageKey.UNKNOWN_USER);
@@ -50,8 +56,8 @@ public class SetEmailCommand implements ExecutableCommand {
}
// Update the player cache
- if (PlayerCache.getInstance().getAuth(playerName) != null) {
- PlayerCache.getInstance().updatePlayer(auth);
+ if (playerCache.getAuth(playerName) != null) {
+ playerCache.updatePlayer(auth);
}
// Show a status message
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 3c36c169..e996e6f0 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
@@ -8,6 +8,7 @@ import fr.xephi.authme.command.help.HelpProvider;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.Arrays;
import java.util.List;
@@ -16,9 +17,11 @@ import java.util.List;
*/
public class SwitchAntiBotCommand implements ExecutableCommand {
+ @Inject
+ private AntiBot antiBot;
+
@Override
public void executeCommand(final CommandSender sender, List arguments, CommandService commandService) {
- AntiBot antiBot = commandService.getAntiBot();
if (arguments.isEmpty()) {
sender.sendMessage("[AuthMe] AntiBot status: " + antiBot.getAntiBotStatus().name());
return;
diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java
index 5c8196dd..c69f9aff 100644
--- a/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/authme/UnregisterAdminCommand.java
@@ -6,6 +6,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
+import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
@@ -19,6 +20,7 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitTask;
+import javax.inject.Inject;
import java.util.List;
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
@@ -28,6 +30,12 @@ import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
*/
public class UnregisterAdminCommand implements ExecutableCommand {
+ @Inject
+ private DataSource dataSource;
+
+ @Inject
+ private PlayerCache playerCache;
+
@Override
public void executeCommand(final CommandSender sender, List arguments, CommandService commandService) {
// Get the player name
@@ -35,20 +43,20 @@ public class UnregisterAdminCommand implements ExecutableCommand {
String playerNameLowerCase = playerName.toLowerCase();
// Make sure the user is valid
- if (!commandService.getDataSource().isAuthAvailable(playerNameLowerCase)) {
+ if (!dataSource.isAuthAvailable(playerNameLowerCase)) {
commandService.send(sender, MessageKey.UNKNOWN_USER);
return;
}
// Remove the player
- if (!commandService.getDataSource().removeAuth(playerNameLowerCase)) {
+ if (!dataSource.removeAuth(playerNameLowerCase)) {
commandService.send(sender, MessageKey.ERROR);
return;
}
// Unregister the player
Player target = commandService.getPlayer(playerNameLowerCase);
- PlayerCache.getInstance().removePlayer(playerNameLowerCase);
+ playerCache.removePlayer(playerNameLowerCase);
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
if (target != null && target.isOnline()) {
if (commandService.getProperty(RegistrationSettings.FORCE)) {
diff --git a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java
index 7d378ca8..67df2d86 100644
--- a/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/changepassword/ChangePasswordCommand.java
@@ -8,6 +8,7 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.task.ChangePasswordTask;
import org.bukkit.entity.Player;
+import javax.inject.Inject;
import java.util.List;
/**
@@ -15,13 +16,15 @@ import java.util.List;
*/
public class ChangePasswordCommand extends PlayerCommand {
+ @Inject
+ private PlayerCache playerCache;
+
@Override
public void runCommand(Player player, List arguments, CommandService commandService) {
String oldPassword = arguments.get(0);
String newPassword = arguments.get(1);
String name = player.getName().toLowerCase();
- final PlayerCache playerCache = commandService.getPlayerCache();
if (!playerCache.isAuthenticated(name)) {
commandService.send(player, MessageKey.NOT_LOGGED_IN);
return;
diff --git a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java
index f4a319a5..56fb5e5c 100644
--- a/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java
+++ b/src/main/java/fr/xephi/authme/command/executable/email/RecoverEmailCommand.java
@@ -8,16 +8,27 @@ import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.PlayerCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
+import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.entity.Player;
+import javax.inject.Inject;
import java.util.List;
public class RecoverEmailCommand extends PlayerCommand {
+ @Inject
+ private PasswordSecurity passwordSecurity;
+
+ @Inject
+ private DataSource dataSource;
+
+ @Inject
+ private PlayerCache playerCache;
+
@Override
public void runCommand(Player player, List arguments, CommandService commandService) {
final String playerMail = arguments.get(0);
@@ -29,7 +40,6 @@ public class RecoverEmailCommand extends PlayerCommand {
commandService.send(player, MessageKey.ERROR);
return;
}
- DataSource dataSource = commandService.getDataSource();
if (dataSource.isAuthAvailable(playerName)) {
if (PlayerCache.getInstance().isAuthenticated(playerName)) {
commandService.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
@@ -37,10 +47,10 @@ public class RecoverEmailCommand extends PlayerCommand {
}
String thePass = RandomString.generate(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH));
- HashedPassword hashNew = commandService.getPasswordSecurity().computeHash(thePass, playerName);
+ HashedPassword hashNew = passwordSecurity.computeHash(thePass, playerName);
PlayerAuth auth;
- if (PlayerCache.getInstance().isAuthenticated(playerName)) {
- auth = PlayerCache.getInstance().getAuth(playerName);
+ if (playerCache.isAuthenticated(playerName)) {
+ auth = playerCache.getAuth(playerName);
} else if (dataSource.isAuthAvailable(playerName)) {
auth = dataSource.getAuth(playerName);
} else {
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 7bc06f03..c5a3ec5f 100644
--- a/src/main/java/fr/xephi/authme/command/help/HelpProvider.java
+++ b/src/main/java/fr/xephi/authme/command/help/HelpProvider.java
@@ -10,10 +10,13 @@ import fr.xephi.authme.command.FoundCommandResult;
import fr.xephi.authme.permission.DefaultPermission;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager;
+import fr.xephi.authme.settings.NewSetting;
+import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.util.CollectionUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@@ -45,9 +48,10 @@ public class HelpProvider {
private final PermissionsManager permissionsManager;
private final String helpHeader;
- public HelpProvider(PermissionsManager permissionsManager, String helpHeader) {
+ @Inject
+ public HelpProvider(PermissionsManager permissionsManager, NewSetting settings) {
this.permissionsManager = permissionsManager;
- this.helpHeader = helpHeader;
+ this.helpHeader = settings.getProperty(PluginSettings.HELP_HEADER);
}
public List printHelp(CommandSender sender, FoundCommandResult result, int options) {
diff --git a/src/main/java/fr/xephi/authme/hooks/PluginHooks.java b/src/main/java/fr/xephi/authme/hooks/PluginHooks.java
index fd455bb1..76f8e034 100644
--- a/src/main/java/fr/xephi/authme/hooks/PluginHooks.java
+++ b/src/main/java/fr/xephi/authme/hooks/PluginHooks.java
@@ -1,19 +1,18 @@
package fr.xephi.authme.hooks;
-import java.io.File;
-
+import com.earth2me.essentials.Essentials;
+import com.onarandombox.MultiverseCore.MultiverseCore;
+import com.onarandombox.MultiverseCore.api.MVWorldManager;
+import fr.xephi.authme.ConsoleLogger;
+import net.minelink.ctplus.CombatTagPlus;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
-import com.earth2me.essentials.Essentials;
-import com.onarandombox.MultiverseCore.MultiverseCore;
-import com.onarandombox.MultiverseCore.api.MVWorldManager;
-
-import fr.xephi.authme.ConsoleLogger;
-import net.minelink.ctplus.CombatTagPlus;
+import javax.inject.Inject;
+import java.io.File;
/**
* Hooks into third-party plugins and allows to perform actions on them.
@@ -30,6 +29,7 @@ public class PluginHooks {
*
* @param pluginManager The server's plugin manager
*/
+ @Inject
public PluginHooks(PluginManager pluginManager) {
this.pluginManager = pluginManager;
tryHookToCombatPlus();
@@ -77,13 +77,23 @@ public class PluginHooks {
return null;
}
+ /**
+ * Checks whether the player is an NPC.
+ *
+ * @param player The player to process
+ * @return True if player is NPC, false otherwise
+ */
+ public boolean isNpc(Player player) {
+ return player.hasMetadata("NPC") || isNpcInCombatTagPlus(player);
+ }
+
/**
* Query the CombatTagPlus plugin whether the given player is an NPC.
*
* @param player The player to verify
* @return True if the player is an NPC according to CombatTagPlus, false if not or if the plugin is unavailable
*/
- public boolean isNpcInCombatTagPlus(Player player) {
+ private boolean isNpcInCombatTagPlus(Player player) {
return combatTagPlus != null && combatTagPlus.getNpcPlayerHelper().isNpc(player);
}
diff --git a/src/main/java/fr/xephi/authme/initialization/AuthMeServiceInitializer.java b/src/main/java/fr/xephi/authme/initialization/AuthMeServiceInitializer.java
new file mode 100644
index 00000000..c2241c11
--- /dev/null
+++ b/src/main/java/fr/xephi/authme/initialization/AuthMeServiceInitializer.java
@@ -0,0 +1,263 @@
+package fr.xephi.authme.initialization;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Provider;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Dependency injector of AuthMe: initializes and injects services and tasks.
+ *
+ * Only constructor and field injection are supported, indicated with the JSR330
+ * {@link javax.inject.Inject @Inject} annotation.
+ *
+ * {@link PostConstruct @PostConstruct} methods are recognized and invoked upon
+ * instantiation. Note that the parent classes are not scanned for such methods.
+ */
+public class AuthMeServiceInitializer {
+
+ private final Set ALLOWED_PACKAGES;
+ private final Map, Object> objects;
+
+ /**
+ * Constructor.
+ *
+ * @param allowedPackages list of allowed packages. Only classes whose package
+ * starts with any of the given entries will be instantiated
+ */
+ public AuthMeServiceInitializer(String... allowedPackages) {
+ ALLOWED_PACKAGES = ImmutableSet.copyOf(allowedPackages);
+ objects = new HashMap<>();
+ objects.put(getClass(), this);
+ }
+
+ /**
+ * Retrieves or instantiates an object of the given type.
+ *
+ * @param clazz the class to retrieve the value for
+ * @param the class' type
+ * @return object of the class' type
+ */
+ public T get(Class clazz) {
+ return get(clazz, new HashSet>());
+ }
+
+ /**
+ * Register an object with a custom class (supertype). Use this for example to specify a
+ * concrete implementation of an interface or an abstract class.
+ *
+ * @param clazz the class to register the object for
+ * @param object the object
+ * @param the class' type
+ */
+ public void register(Class super T> clazz, T object) {
+ if (objects.containsKey(clazz)) {
+ throw new IllegalStateException("There is already an object present for " + clazz);
+ }
+ Preconditions.checkNotNull(object);
+ objects.put(clazz, object);
+ }
+
+ /**
+ * Associate an annotation with a value.
+ *
+ * @param annotation the annotation
+ * @param value the value
+ */
+ public void provide(Class extends Annotation> annotation, Object value) {
+ if (objects.containsKey(annotation)) {
+ throw new IllegalStateException("Annotation @" + annotation.getClass().getSimpleName()
+ + " already registered");
+ }
+ Preconditions.checkNotNull(value);
+ objects.put(annotation, value);
+ }
+
+ /**
+ * Creates a new instance of the given class and does not keep track of it afterwards,
+ * unlike {@link #get(Class)} (singleton scope).
+ *
+ * @param clazz the class to instantiate
+ * @param the class' type
+ * @return new instance of class T
+ */
+ public T newInstance(Class clazz) {
+ return instantiate(clazz, new HashSet>());
+ }
+
+ /**
+ * 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.
+ *
+ * @param clazz the class to retrieve a value for
+ * @param traversedClasses the list of traversed classes
+ * @param the class' type
+ * @return instance or associated value (for annotations)
+ */
+ private T get(Class clazz, Set> traversedClasses) {
+ if (Annotation.class.isAssignableFrom(clazz)) {
+ throw new UnsupportedOperationException("Cannot retrieve annotated elements in this way!");
+ } else if (objects.containsKey(clazz)) {
+ return clazz.cast(objects.get(clazz));
+ }
+
+ // First time we come across clazz, need to instantiate it. Validate that we can do so
+ validatePackage(clazz);
+ validateInstantiable(clazz);
+
+ // Add the clazz to the list of traversed classes in a new Set, so each path we take has its own Set.
+ traversedClasses = new HashSet<>(traversedClasses);
+ traversedClasses.add(clazz);
+ T object = instantiate(clazz, traversedClasses);
+ storeObject(object);
+ return object;
+ }
+
+ /**
+ * Instantiates the given class by locating an @Inject constructor and retrieving
+ * or instantiating its parameters.
+ *
+ * @param clazz the class to instantiate
+ * @param traversedClasses collection of classes already traversed
+ * @param the class' type
+ * @return the instantiated object
+ */
+ private T instantiate(Class clazz, Set> traversedClasses) {
+ Injection injection = firstNotNull(ConstructorInjection.provide(clazz), FieldInjection.provide(clazz));
+ if (injection == null) {
+ throw new IllegalStateException("Did not find injection method for " + clazz + ". Make sure you have "
+ + "a constructor with @Inject or fields with @Inject. Fields with @Inject require "
+ + "the default constructor");
+ }
+
+ validateInjectionHasNoCircularDependencies(injection.getDependencies(), traversedClasses);
+ Object[] dependencies = resolveDependencies(injection, traversedClasses);
+ T object = injection.instantiateWith(dependencies);
+ executePostConstructMethods(object);
+ return object;
+ }
+
+ /**
+ * Resolves the dependencies for the given constructor, i.e. returns a collection that satisfy
+ * the constructor's parameter types by retrieving elements or instantiating them where necessary.
+ *
+ * @param injection the injection parameters
+ * @param traversedClasses collection of traversed classes
+ * @return array with the parameters to use in the constructor
+ */
+ private Object[] resolveDependencies(Injection> injection, Set> traversedClasses) {
+ Class>[] dependencies = injection.getDependencies();
+ Class>[] annotations = injection.getDependencyAnnotations();
+ Object[] values = new Object[dependencies.length];
+ for (int i = 0; i < dependencies.length; ++i) {
+ if (annotations[i] != null) {
+ Object value = objects.get(annotations[i]);
+ if (value == null) {
+ throw new IllegalStateException("Value for field with @" + annotations[i].getSimpleName()
+ + " must be registered beforehand");
+ }
+ values[i] = value;
+ } else {
+ values[i] = get(dependencies[i], traversedClasses);
+ }
+ }
+ return values;
+ }
+
+ /**
+ * Stores the given object with its class as key. Throws an exception if the key already has
+ * a value associated to it.
+ *
+ * @param object the object to store
+ */
+ private void storeObject(Object object) {
+ if (objects.containsKey(object.getClass())) {
+ throw new IllegalStateException("There is already an object present for " + object.getClass());
+ }
+ Preconditions.checkNotNull(object);
+ objects.put(object.getClass(), object);
+ }
+
+ /**
+ * Validates that none of the dependencies' types are present in the given collection
+ * of traversed classes. This prevents circular dependencies.
+ *
+ * @param dependencies the dependencies of the class
+ * @param traversedClasses the collection of traversed classes
+ */
+ private static void validateInjectionHasNoCircularDependencies(Class>[] dependencies,
+ Set> traversedClasses) {
+ for (Class> clazz : dependencies) {
+ if (traversedClasses.contains(clazz)) {
+ throw new IllegalStateException("Found cyclic dependency - already traversed '" + clazz
+ + "' (full traversal list: " + traversedClasses + ")");
+ }
+ }
+ }
+
+ /**
+ * Validates the package of a parameter type to ensure that it is part of the allowed packages.
+ * This ensures that we don't try to instantiate things that are beyond our reach in case some
+ * external parameter type has not been registered.
+ *
+ * @param clazz the class to validate
+ */
+ private void validatePackage(Class> clazz) {
+ if (clazz.getPackage() == null) {
+ throw new IllegalStateException("Primitive types must be provided explicitly (or use an annotation).");
+ }
+ String packageName = clazz.getPackage().getName();
+ for (String allowedPackage : ALLOWED_PACKAGES) {
+ if (packageName.startsWith(allowedPackage)) {
+ return;
+ }
+ }
+ throw new IllegalStateException("Class " + clazz + " with package " + packageName + " is outside of the "
+ + "allowed packages. It must be provided explicitly or the package must be passed to the constructor.");
+ }
+
+ private static void executePostConstructMethods(Object object) {
+ for (Method method : object.getClass().getDeclaredMethods()) {
+ if (method.isAnnotationPresent(PostConstruct.class)) {
+ if (method.getParameterTypes().length == 0 && !Modifier.isStatic(method.getModifiers())) {
+ try {
+ method.setAccessible(true);
+ method.invoke(object);
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ } else {
+ throw new IllegalStateException(String.format("@PostConstruct methods may not be static or have "
+ + " any parameters. Method '%s' of class '%s' is either static or has parameters",
+ method.getName(), object.getClass().getSimpleName()));
+ }
+ }
+ }
+ }
+
+ private static void validateInstantiable(Class> clazz) {
+ if (clazz.isEnum() || clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
+ throw new IllegalStateException("Class " + clazz.getSimpleName() + " cannot be instantiated");
+ }
+ }
+
+ @SafeVarargs
+ private static Injection firstNotNull(Provider extends Injection>... providers) {
+ for (Provider extends Injection> provider : providers) {
+ Injection object = provider.get();
+ if (object != null) {
+ return object;
+ }
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/fr/xephi/authme/initialization/BaseCommands.java b/src/main/java/fr/xephi/authme/initialization/BaseCommands.java
new file mode 100644
index 00000000..8ff263ab
--- /dev/null
+++ b/src/main/java/fr/xephi/authme/initialization/BaseCommands.java
@@ -0,0 +1,14 @@
+package fr.xephi.authme.initialization;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation to denote the collection of AuthMe commands.
+ */
+@Target({ElementType.PARAMETER, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface BaseCommands {
+}
diff --git a/src/main/java/fr/xephi/authme/initialization/ConstructorInjection.java b/src/main/java/fr/xephi/authme/initialization/ConstructorInjection.java
new file mode 100644
index 00000000..e80ea128
--- /dev/null
+++ b/src/main/java/fr/xephi/authme/initialization/ConstructorInjection.java
@@ -0,0 +1,86 @@
+package fr.xephi.authme.initialization;
+
+import com.google.common.base.Preconditions;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Functionality for constructor injection.
+ */
+class ConstructorInjection implements Injection {
+
+ private final Constructor constructor;
+
+ private ConstructorInjection(Constructor constructor) {
+ this.constructor = constructor;
+ }
+
+ @Override
+ public Class>[] getDependencies() {
+ return constructor.getParameterTypes();
+ }
+
+ @Override
+ public Class>[] getDependencyAnnotations() {
+ Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
+ Class>[] annotations = new Class>[parameterAnnotations.length];
+ for (int i = 0; i < parameterAnnotations.length; ++i) {
+ annotations[i] = parameterAnnotations[i].length > 0
+ ? parameterAnnotations[i][0].annotationType()
+ : null;
+ }
+ return annotations;
+ }
+
+ @Override
+ public T instantiateWith(Object... values) {
+ validateNoNullValues(values);
+ try {
+ return constructor.newInstance(values);
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+
+ public static Provider> provide(final Class clazz) {
+ return new Provider>() {
+ @Override
+ public ConstructorInjection get() {
+ Constructor constructor = getInjectionConstructor(clazz);
+ return constructor == null ? null : new ConstructorInjection<>(constructor);
+ }
+ };
+ }
+
+
+ /**
+ * Gets the first found constructor annotated with {@link Inject} of the given class
+ * and marks it as accessible.
+ *
+ * @param clazz the class to process
+ * @param the class' type
+ * @return injection constructor for the class, null if not applicable
+ */
+ @SuppressWarnings("unchecked")
+ private static Constructor getInjectionConstructor(Class clazz) {
+ Constructor>[] constructors = clazz.getDeclaredConstructors();
+ for (Constructor> constructor : constructors) {
+ if (constructor.isAnnotationPresent(Inject.class)) {
+ constructor.setAccessible(true);
+ return (Constructor) constructor;
+ }
+ }
+ return null;
+ }
+
+ private static void validateNoNullValues(Object[] array) {
+ for (Object entry : array) {
+ Preconditions.checkNotNull(entry);
+ }
+ }
+
+}
diff --git a/src/main/java/fr/xephi/authme/initialization/DataFolder.java b/src/main/java/fr/xephi/authme/initialization/DataFolder.java
new file mode 100644
index 00000000..0288f45a
--- /dev/null
+++ b/src/main/java/fr/xephi/authme/initialization/DataFolder.java
@@ -0,0 +1,14 @@
+package fr.xephi.authme.initialization;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation for specifying the plugin's data folder.
+ */
+@Target({ElementType.PARAMETER, ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DataFolder {
+}
diff --git a/src/main/java/fr/xephi/authme/initialization/FieldInjection.java b/src/main/java/fr/xephi/authme/initialization/FieldInjection.java
new file mode 100644
index 00000000..1e7973e2
--- /dev/null
+++ b/src/main/java/fr/xephi/authme/initialization/FieldInjection.java
@@ -0,0 +1,127 @@
+package fr.xephi.authme.initialization;
+
+import com.google.common.base.Preconditions;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Functionality for field injection.
+ */
+class FieldInjection implements Injection {
+
+ private final Field[] fields;
+ private final Constructor defaultConstructor;
+
+ private FieldInjection(Constructor defaultConstructor, Collection fields) {
+ this.fields = fields.toArray(new Field[fields.size()]);
+ this.defaultConstructor = defaultConstructor;
+ }
+
+ @Override
+ public Class>[] getDependencies() {
+ Class>[] types = new Class>[fields.length];
+ for (int i = 0; i < fields.length; ++i) {
+ types[i] = fields[i].getType();
+ }
+ return types;
+ }
+
+ @Override
+ public Class>[] getDependencyAnnotations() {
+ Class>[] annotations = new Class>[fields.length];
+ for (int i = 0; i < fields.length; ++i) {
+ annotations[i] = getFirstNonInjectAnnotation(fields[i]);
+ }
+ return annotations;
+ }
+
+ @Override
+ public T instantiateWith(Object... values) {
+ Preconditions.checkArgument(values.length == fields.length,
+ "The number of values must be equal to the number of fields");
+
+ T instance;
+ try {
+ instance = defaultConstructor.newInstance();
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
+ throw new UnsupportedOperationException(e);
+ }
+
+ for (int i = 0; i < fields.length; ++i) {
+ try {
+ Preconditions.checkNotNull(values[i]);
+ fields[i].set(instance, values[i]);
+ } catch (IllegalAccessException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * Returns a provider for a {@code FieldInjection} instance, i.e. a provides an object
+ * with which field injection can be performed on the given class if applicable. The provided
+ * value is {@code null} if field injection cannot be applied to the class.
+ *
+ * @param clazz the class to provide field injection for
+ * @param the class' type
+ * @return field injection provider for the given class
+ */
+ public static Provider> provide(final Class clazz) {
+ return new Provider>() {
+ @Override
+ public FieldInjection get() {
+ Constructor constructor = getDefaultConstructor(clazz);
+ if (constructor == null) {
+ return null;
+ }
+ List fields = getInjectionFields(clazz);
+ return fields == null ? null : new FieldInjection<>(constructor, fields);
+ }
+ };
+ }
+
+ private static List getInjectionFields(Class> clazz) {
+ List fields = new ArrayList<>();
+ for (Field field : clazz.getDeclaredFields()) {
+ if (field.isAnnotationPresent(Inject.class)) {
+ if (Modifier.isStatic(field.getModifiers())) {
+ throw new IllegalStateException(String.format("Field '%s' in class '%s' is static but "
+ + "annotated with @Inject", field.getName(), clazz.getSimpleName()));
+ }
+ field.setAccessible(true);
+ fields.add(field);
+ }
+ }
+ return fields;
+ }
+
+ private static Class> getFirstNonInjectAnnotation(Field field) {
+ for (Annotation annotation : field.getAnnotations()) {
+ if (annotation.annotationType() != Inject.class) {
+ return annotation.annotationType();
+ }
+ }
+ return null;
+ }
+
+ private static Constructor getDefaultConstructor(Class clazz) {
+ try {
+ Constructor> defaultConstructor = clazz.getDeclaredConstructor();
+ defaultConstructor.setAccessible(true);
+ return (Constructor) defaultConstructor;
+ } catch (NoSuchMethodException ignore) {
+ // no default constructor available
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/fr/xephi/authme/initialization/Injection.java b/src/main/java/fr/xephi/authme/initialization/Injection.java
new file mode 100644
index 00000000..6e85b4ce
--- /dev/null
+++ b/src/main/java/fr/xephi/authme/initialization/Injection.java
@@ -0,0 +1,36 @@
+package fr.xephi.authme.initialization;
+
+/**
+ * Common interface for all injection methods.
+ *
+ * @param the type of the concerned object
+ */
+interface Injection {
+
+ /**
+ * Returns the dependencies that must be provided to instantiate the given item.
+ *
+ * @return list of dependencies
+ * @see #instantiateWith
+ */
+ Class>[] getDependencies();
+
+ /**
+ * Returns the annotation on each dependency if available. The indices of this
+ * array correspond to the ones of {@link #getDependencies()}. If no annotation
+ * is available, {@code null} is stored. If multiple annotations are present, only
+ * one is stored (no guarantee on which one).
+ *
+ * @return annotation for each dependency
+ */
+ Class>[] getDependencyAnnotations();
+
+ /**
+ * Creates a new instance with the given values as dependencies. The given values
+ * must correspond to {@link #getDependencies()} in size, order and type.
+ *
+ * @param values the values to set for the dependencies
+ * @return resulting object
+ */
+ T instantiateWith(Object... values);
+}
diff --git a/src/main/java/fr/xephi/authme/MetricsStarter.java b/src/main/java/fr/xephi/authme/initialization/MetricsStarter.java
similarity index 93%
rename from src/main/java/fr/xephi/authme/MetricsStarter.java
rename to src/main/java/fr/xephi/authme/initialization/MetricsStarter.java
index eac9ebaf..4a163f98 100644
--- a/src/main/java/fr/xephi/authme/MetricsStarter.java
+++ b/src/main/java/fr/xephi/authme/initialization/MetricsStarter.java
@@ -1,5 +1,7 @@
-package fr.xephi.authme;
+package fr.xephi.authme.initialization;
+import fr.xephi.authme.AuthMe;
+import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java
index e3753793..a0fa4011 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java
@@ -18,6 +18,7 @@ import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings;
+import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
@@ -54,6 +55,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
+import javax.inject.Inject;
import java.util.concurrent.ConcurrentHashMap;
import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent;
@@ -68,27 +70,24 @@ public class AuthMePlayerListener implements Listener {
public static final ConcurrentHashMap joinMessage = new ConcurrentHashMap<>();
public static final ConcurrentHashMap causeByAuthMe = new ConcurrentHashMap<>();
- private final AuthMe plugin;
- private final NewSetting settings;
- private final Messages m;
- private final DataSource dataSource;
- private final AntiBot antiBot;
- private final Management management;
- private final BukkitService bukkitService;
- private final ValidationService validationService;
-
- public AuthMePlayerListener(AuthMe plugin, NewSetting settings, Messages messages, DataSource dataSource,
- AntiBot antiBot, Management management, BukkitService bukkitService,
- ValidationService validationService) {
- this.plugin = plugin;
- this.settings = settings;
- this.m = messages;
- this.dataSource = dataSource;
- this.antiBot = antiBot;
- this.management = management;
- this.bukkitService = bukkitService;
- this.validationService = validationService;
- }
+ @Inject
+ private AuthMe plugin;
+ @Inject
+ private NewSetting settings;
+ @Inject
+ private Messages m;
+ @Inject
+ private DataSource dataSource;
+ @Inject
+ private AntiBot antiBot;
+ @Inject
+ private Management management;
+ @Inject
+ private BukkitService bukkitService;
+ @Inject
+ private SpawnLoader spawnLoader;
+ @Inject
+ private ValidationService validationService;
private void handleChat(AsyncPlayerChatEvent event) {
if (settings.getProperty(RestrictionSettings.ALLOW_CHAT)) {
@@ -205,7 +204,7 @@ public class AuthMePlayerListener implements Listener {
return;
}
- Location spawn = plugin.getSpawnLocation(player);
+ Location spawn = spawnLoader.getSpawnLocation(player);
if (spawn != null && spawn.getWorld() != null) {
if (!player.getWorld().equals(spawn.getWorld())) {
player.teleport(spawn);
@@ -513,7 +512,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer();
String name = player.getName().toLowerCase();
- Location spawn = plugin.getSpawnLocation(player);
+ Location spawn = spawnLoader.getSpawnLocation(player);
if (Settings.isSaveQuitLocationEnabled && dataSource.isAuthAvailable(name)) {
PlayerAuth auth = PlayerAuth.builder()
.name(name)
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener19.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener19.java
index 5e6525bb..8be48ba2 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener19.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener19.java
@@ -7,16 +7,17 @@ import org.spigotmc.event.player.PlayerSpawnLocationEvent;
import fr.xephi.authme.AuthMe;
+import javax.inject.Inject;
+
/**
* Listener of player events for events introduced in Minecraft 1.9.
*/
public class AuthMePlayerListener19 implements Listener {
- private final AuthMe plugin;
+ @Inject
+ private AuthMe plugin;
- public AuthMePlayerListener19(AuthMe plugin) {
- this.plugin = plugin;
- }
+ public AuthMePlayerListener19() { }
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerSpawn(PlayerSpawnLocationEvent event) {
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java
index 96f5320a..bb85374d 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java
@@ -16,26 +16,24 @@ import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListPingEvent;
+import javax.inject.Inject;
+
/**
*/
public class AuthMeServerListener implements Listener {
- private final AuthMe plugin;
- private final Messages messages;
- private final NewSetting settings;
- private final PluginHooks pluginHooks;
- private final SpawnLoader spawnLoader;
- private final ValidationService validationService;
-
- public AuthMeServerListener(AuthMe plugin, Messages messages, NewSetting settings, PluginHooks pluginHooks,
- SpawnLoader spawnLoader, ValidationService validationService) {
- this.plugin = plugin;
- this.messages = messages;
- this.settings = settings;
- this.pluginHooks = pluginHooks;
- this.spawnLoader = spawnLoader;
- this.validationService = validationService;
- }
+ @Inject
+ private AuthMe plugin;
+ @Inject
+ private Messages messages;
+ @Inject
+ private NewSetting settings;
+ @Inject
+ private PluginHooks pluginHooks;
+ @Inject
+ private SpawnLoader spawnLoader;
+ @Inject
+ private ValidationService validationService;
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerPing(ServerListPingEvent event) {
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeTabCompletePacketAdapter.java b/src/main/java/fr/xephi/authme/listener/AuthMeTabCompletePacketAdapter.java
index d8266985..ae6c47bc 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMeTabCompletePacketAdapter.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMeTabCompletePacketAdapter.java
@@ -11,8 +11,11 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache;
+import javax.inject.Inject;
+
public class AuthMeTabCompletePacketAdapter extends PacketAdapter {
+ @Inject
public AuthMeTabCompletePacketAdapter(AuthMe plugin) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Client.TAB_COMPLETE);
}
diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeTablistPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/AuthMeTablistPacketAdapter.java
index 6d4ea8ba..17b4a60a 100644
--- a/src/main/java/fr/xephi/authme/listener/AuthMeTablistPacketAdapter.java
+++ b/src/main/java/fr/xephi/authme/listener/AuthMeTablistPacketAdapter.java
@@ -14,14 +14,13 @@ import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
-
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.util.BukkitService;
-
import org.bukkit.entity.Player;
+import javax.inject.Inject;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.logging.Level;
@@ -30,6 +29,7 @@ public class AuthMeTablistPacketAdapter extends PacketAdapter {
private final BukkitService bukkitService;
+ @Inject
public AuthMeTablistPacketAdapter(AuthMe plugin, BukkitService bukkitService) {
super(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO);
this.bukkitService = bukkitService;
diff --git a/src/main/java/fr/xephi/authme/ImageGenerator.java b/src/main/java/fr/xephi/authme/mail/ImageGenerator.java
similarity index 88%
rename from src/main/java/fr/xephi/authme/ImageGenerator.java
rename to src/main/java/fr/xephi/authme/mail/ImageGenerator.java
index e529efab..77d98901 100644
--- a/src/main/java/fr/xephi/authme/ImageGenerator.java
+++ b/src/main/java/fr/xephi/authme/mail/ImageGenerator.java
@@ -1,6 +1,9 @@
-package fr.xephi.authme;
+package fr.xephi.authme.mail;
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.GradientPaint;
+import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
/**
diff --git a/src/main/java/fr/xephi/authme/mail/SendMailSSL.java b/src/main/java/fr/xephi/authme/mail/SendMailSSL.java
index c80001c3..d8332602 100644
--- a/src/main/java/fr/xephi/authme/mail/SendMailSSL.java
+++ b/src/main/java/fr/xephi/authme/mail/SendMailSSL.java
@@ -2,7 +2,6 @@ package fr.xephi.authme.mail;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
-import fr.xephi.authme.ImageGenerator;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.EmailSettings;
diff --git a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
index ee27f82c..7dfcd40c 100644
--- a/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
+++ b/src/main/java/fr/xephi/authme/permission/PermissionsManager.java
@@ -2,6 +2,7 @@ package fr.xephi.authme.permission;
import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.CalculableType;
+import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandDescription;
import fr.xephi.authme.util.CollectionUtils;
import net.milkbowl.vault.permission.Permission;
@@ -20,11 +21,12 @@ import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.logging.Logger;
/**
*
@@ -48,10 +50,7 @@ public class PermissionsManager implements PermissionsService {
* Server instance.
*/
private final Server server;
- /**
- * Logger instance.
- */
- private Logger log;
+ private final PluginManager pluginManager;
/**
* Type of permissions system that is currently used.
* Null if no permissions system is hooked and/or used.
@@ -70,11 +69,11 @@ public class PermissionsManager implements PermissionsService {
* Constructor.
*
* @param server Server instance
- * @param log Logger
*/
- public PermissionsManager(Server server, Logger log) {
+ @Inject
+ public PermissionsManager(Server server, PluginManager pluginManager) {
this.server = server;
- this.log = log;
+ this.pluginManager = pluginManager;
}
/**
@@ -100,39 +99,37 @@ public class PermissionsManager implements PermissionsService {
*
* @return The detected permissions system.
*/
+ @PostConstruct
public PermissionsSystemType setup() {
// Force-unhook from current hooked permissions systems
unhook();
- // Define the plugin manager
- final PluginManager pluginManager = this.server.getPluginManager();
-
// Reset used permissions system type flag
permsType = null;
// Loop through all the available permissions system types
- for(PermissionsSystemType type : PermissionsSystemType.values()) {
+ for (PermissionsSystemType type : PermissionsSystemType.values()) {
// Try to find and hook the current plugin if available, print an error if failed
try {
// Try to find the plugin for the current permissions system
Plugin plugin = pluginManager.getPlugin(type.getPluginName());
// Make sure a plugin with this name was found
- if(plugin == null)
+ if (plugin == null)
continue;
// Make sure the plugin is enabled before hooking
- if(!plugin.isEnabled()) {
- this.log.info("Not hooking into " + type.getName() + " because it's disabled!");
+ if (!plugin.isEnabled()) {
+ ConsoleLogger.info("Not hooking into " + type.getName() + " because it's disabled!");
continue;
}
// Use the proper method to hook this plugin
- switch(type) {
+ switch (type) {
case PERMISSIONS_EX:
// Get the permissions manager for PermissionsEx and make sure it isn't null
- if(PermissionsEx.getPermissionManager() == null) {
- this.log.info("Failed to hook into " + type.getName() + "!");
+ if (PermissionsEx.getPermissionManager() == null) {
+ ConsoleLogger.info("Failed to hook into " + type.getName() + "!");
continue;
}
@@ -146,8 +143,8 @@ public class PermissionsManager implements PermissionsService {
case Z_PERMISSIONS:
// Set the zPermissions service and make sure it's valid
zPermissionsService = Bukkit.getServicesManager().load(ZPermissionsService.class);
- if(zPermissionsService == null) {
- this.log.info("Failed to hook into " + type.getName() + "!");
+ if (zPermissionsService == null) {
+ ConsoleLogger.info("Failed to hook into " + type.getName() + "!");
continue;
}
@@ -157,14 +154,14 @@ public class PermissionsManager implements PermissionsService {
// Get the permissions provider service
RegisteredServiceProvider permissionProvider = this.server.getServicesManager().getRegistration(Permission.class);
if (permissionProvider == null) {
- this.log.info("Failed to hook into " + type.getName() + "!");
+ ConsoleLogger.info("Failed to hook into " + type.getName() + "!");
continue;
}
// Get the Vault provider and make sure it's valid
vaultPerms = permissionProvider.getProvider();
- if(vaultPerms == null) {
- this.log.info("Not using " + type.getName() + " because it's disabled!");
+ if (vaultPerms == null) {
+ ConsoleLogger.info("Not using " + type.getName() + " because it's disabled!");
continue;
}
@@ -177,19 +174,19 @@ public class PermissionsManager implements PermissionsService {
this.permsType = type;
// Show a success message
- this.log.info("Hooked into " + type.getName() + "!");
+ ConsoleLogger.info("Hooked into " + type.getName() + "!");
// Return the used permissions system type
return type;
} catch (Exception ex) {
// An error occurred, show a warning message
- this.log.info("Error while hooking into " + type.getName() + "!");
+ ConsoleLogger.logException("Error while hooking into " + type.getName(), ex);
}
}
// No recognized permissions system found, show a message and return
- this.log.info("No supported permissions system found! Permissions are disabled!");
+ ConsoleLogger.info("No supported permissions system found! Permissions are disabled!");
return null;
}
@@ -201,7 +198,7 @@ public class PermissionsManager implements PermissionsService {
this.permsType = null;
// Print a status message to the console
- this.log.info("Unhooked from Permissions!");
+ ConsoleLogger.info("Unhooked from Permissions!");
}
/**
@@ -232,7 +229,7 @@ public class PermissionsManager implements PermissionsService {
if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
pluginName.equals("bPermissions") || pluginName.equals("GroupManager") ||
pluginName.equals("zPermissions") || pluginName.equals("Vault")) {
- this.log.info(pluginName + " plugin enabled, dynamically updating permissions hooks!");
+ ConsoleLogger.info(pluginName + " plugin enabled, dynamically updating permissions hooks!");
setup();
}
}
@@ -251,7 +248,7 @@ public class PermissionsManager implements PermissionsService {
if (pluginName.equals("PermissionsEx") || pluginName.equals("PermissionsBukkit") ||
pluginName.equals("bPermissions") || pluginName.equals("GroupManager") ||
pluginName.equals("zPermissions") || pluginName.equals("Vault")) {
- this.log.info(pluginName + " plugin disabled, updating hooks!");
+ ConsoleLogger.info(pluginName + " plugin disabled, updating hooks!");
setup();
}
}
diff --git a/src/main/java/fr/xephi/authme/process/Management.java b/src/main/java/fr/xephi/authme/process/Management.java
index 4b279c9a..04a0f414 100644
--- a/src/main/java/fr/xephi/authme/process/Management.java
+++ b/src/main/java/fr/xephi/authme/process/Management.java
@@ -3,6 +3,7 @@ package fr.xephi.authme.process;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
+import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.process.email.AsyncAddEmail;
import fr.xephi.authme.process.email.AsyncChangeEmail;
import fr.xephi.authme.process.join.AsynchronousJoin;
@@ -14,23 +15,26 @@ import fr.xephi.authme.process.unregister.AsynchronousUnregister;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
+import javax.inject.Inject;
+
/**
*/
public class Management {
- private final AuthMe plugin;
- private final BukkitScheduler sched;
- private final ProcessService processService;
- private final DataSource dataSource;
- private final PlayerCache playerCache;
+ @Inject
+ private AuthMe plugin;
+ @Inject
+ private BukkitScheduler sched;
+ @Inject
+ private ProcessService processService;
+ @Inject
+ private DataSource dataSource;
+ @Inject
+ private PlayerCache playerCache;
+ @Inject
+ private PluginHooks pluginHooks;
- public Management(AuthMe plugin, ProcessService processService, DataSource dataSource, PlayerCache playerCache) {
- this.plugin = plugin;
- this.sched = this.plugin.getServer().getScheduler();
- this.processService = processService;
- this.dataSource = dataSource;
- this.playerCache = playerCache;
- }
+ Management() { }
public void performLogin(final Player player, final String password, final boolean forceLogin) {
runTask(new AsynchronousLogin(player, password, forceLogin, plugin, dataSource, processService));
@@ -49,7 +53,7 @@ public class Management {
}
public void performJoin(final Player player) {
- runTask(new AsynchronousJoin(player, plugin, dataSource, playerCache, processService));
+ runTask(new AsynchronousJoin(player, plugin, dataSource, playerCache, pluginHooks, processService));
}
public void performQuit(final Player player, final boolean isKick) {
diff --git a/src/main/java/fr/xephi/authme/process/ProcessService.java b/src/main/java/fr/xephi/authme/process/ProcessService.java
index 653be156..a338cad4 100644
--- a/src/main/java/fr/xephi/authme/process/ProcessService.java
+++ b/src/main/java/fr/xephi/authme/process/ProcessService.java
@@ -17,6 +17,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.scheduler.BukkitTask;
+import javax.inject.Inject;
import java.util.Collection;
/**
@@ -24,29 +25,24 @@ import java.util.Collection;
*/
public class ProcessService {
- private final NewSetting settings;
- private final Messages messages;
- private final AuthMe authMe;
- private final DataSource dataSource;
- private final PasswordSecurity passwordSecurity;
- private final PluginHooks pluginHooks;
- private final SpawnLoader spawnLoader;
- private final ValidationService validationService;
- private final BukkitService bukkitService;
-
- public ProcessService(NewSetting settings, Messages messages, AuthMe authMe, DataSource dataSource,
- PasswordSecurity passwordSecurity, PluginHooks pluginHooks, SpawnLoader spawnLoader,
- ValidationService validationService, BukkitService bukkitService) {
- this.settings = settings;
- this.messages = messages;
- this.authMe = authMe;
- this.dataSource = dataSource;
- this.passwordSecurity = passwordSecurity;
- this.pluginHooks = pluginHooks;
- this.spawnLoader = spawnLoader;
- this.validationService = validationService;
- this.bukkitService = bukkitService;
- }
+ @Inject
+ private NewSetting settings;
+ @Inject
+ private Messages messages;
+ @Inject
+ private AuthMe authMe;
+ @Inject
+ private DataSource dataSource;
+ @Inject
+ private PasswordSecurity passwordSecurity;
+ @Inject
+ private PluginHooks pluginHooks;
+ @Inject
+ private SpawnLoader spawnLoader;
+ @Inject
+ private ValidationService validationService;
+ @Inject
+ private BukkitService bukkitService;
/**
* Retrieve a property's value.
diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java
index 37b0dfbd..c9ab7159 100644
--- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java
+++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java
@@ -9,6 +9,7 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent;
+import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.PlayerStatePermission;
@@ -45,18 +46,20 @@ public class AsynchronousJoin implements Process {
private final String name;
private final ProcessService service;
private final PlayerCache playerCache;
+ private final PluginHooks pluginHooks;
private final boolean disableCollisions = MethodUtils
.getAccessibleMethod(LivingEntity.class, "setCollidable", new Class[]{}) != null;
public AsynchronousJoin(Player player, AuthMe plugin, DataSource database, PlayerCache playerCache,
- ProcessService service) {
+ PluginHooks pluginHooks, ProcessService service) {
this.player = player;
this.plugin = plugin;
this.database = database;
this.name = player.getName().toLowerCase();
this.service = service;
this.playerCache = playerCache;
+ this.pluginHooks = pluginHooks;
}
@Override
@@ -190,7 +193,7 @@ public class AsynchronousJoin implements Process {
player.setWalkSpeed(0.0f);
}
player.setNoDamageTicks(registrationTimeout);
- if (plugin.getPluginHooks().isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
+ if (pluginHooks.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) {
player.performCommand("motd");
}
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
diff --git a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java
index 94a8abeb..4a525531 100644
--- a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java
+++ b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java
@@ -2,32 +2,43 @@ package fr.xephi.authme.security;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.PasswordEncryptionEvent;
+import fr.xephi.authme.initialization.AuthMeServiceInitializer;
import fr.xephi.authme.security.crypts.EncryptionMethod;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.plugin.PluginManager;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
/**
* Manager class for password-related operations.
*/
public class PasswordSecurity {
- private final NewSetting settings;
+ @Inject
+ private NewSetting settings;
+
+ @Inject
+ private DataSource dataSource;
+
+ @Inject
+ private PluginManager pluginManager;
+
+ @Inject
+ private AuthMeServiceInitializer initializer;
+
private HashAlgorithm algorithm;
private boolean supportOldAlgorithm;
- private final DataSource dataSource;
- private final PluginManager pluginManager;
- public PasswordSecurity(DataSource dataSource, NewSetting settings, PluginManager pluginManager) {
- this.settings = settings;
+ /**
+ * Load or reload the configuration.
+ */
+ @PostConstruct
+ public void reload() {
this.algorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH);
this.supportOldAlgorithm = settings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH);
- this.dataSource = dataSource;
- this.pluginManager = pluginManager;
}
/**
@@ -73,14 +84,6 @@ public class PasswordSecurity {
|| supportOldAlgorithm && compareWithAllEncryptionMethods(password, hashedPassword, playerLowerCase);
}
- /**
- * Reload the configuration.
- */
- public void reload() {
- this.algorithm = settings.getProperty(SecuritySettings.PASSWORD_HASH);
- this.supportOldAlgorithm = settings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH);
- }
-
/**
* Compare the given hash with all available encryption methods to support
* the migration to a new encryption method. Upon a successful match, the password
@@ -95,7 +98,7 @@ public class PasswordSecurity {
private boolean compareWithAllEncryptionMethods(String password, HashedPassword hashedPassword, String playerName) {
for (HashAlgorithm algorithm : HashAlgorithm.values()) {
if (!HashAlgorithm.CUSTOM.equals(algorithm)) {
- EncryptionMethod method = initializeEncryptionMethod(algorithm, settings);
+ EncryptionMethod method = initializeEncryptionMethod(algorithm);
if (methodMatches(method, password, hashedPassword, playerName)) {
hashPasswordForNewAlgorithm(password, playerName);
return true;
@@ -133,7 +136,7 @@ public class PasswordSecurity {
* @return The encryption method
*/
private EncryptionMethod initializeEncryptionMethodWithEvent(HashAlgorithm algorithm, String playerName) {
- EncryptionMethod method = initializeEncryptionMethod(algorithm, settings);
+ EncryptionMethod method = initializeEncryptionMethod(algorithm);
PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName);
pluginManager.callEvent(event);
return event.getMethod();
@@ -143,30 +146,14 @@ public class PasswordSecurity {
* Initialize the encryption method associated with the given hash algorithm.
*
* @param algorithm The algorithm to retrieve the encryption method for
- * @param settings The settings instance to pass to the constructor if required
*
* @return The associated encryption method, or null if CUSTOM / deprecated
*/
- public static EncryptionMethod initializeEncryptionMethod(HashAlgorithm algorithm,
- NewSetting settings) {
- try {
- if (HashAlgorithm.CUSTOM.equals(algorithm) || HashAlgorithm.PLAINTEXT.equals(algorithm)) {
- return null;
- }
- Constructor> constructor = algorithm.getClazz().getConstructors()[0];
- Class>[] parameters = constructor.getParameterTypes();
- if (parameters.length == 0) {
- return (EncryptionMethod) constructor.newInstance();
- } else if (parameters.length == 1 && parameters[0] == NewSetting.class) {
- return (EncryptionMethod) constructor.newInstance(settings);
- } else {
- throw new UnsupportedOperationException("Did not find default constructor or constructor with settings "
- + "parameter in class " + algorithm.getClazz().getSimpleName());
- }
- } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
- throw new UnsupportedOperationException("Constructor for '" + algorithm.getClazz().getSimpleName()
- + "' could not be invoked. (Is there no default constructor?)", e);
+ public EncryptionMethod initializeEncryptionMethod(HashAlgorithm algorithm) {
+ if (HashAlgorithm.CUSTOM.equals(algorithm) || HashAlgorithm.PLAINTEXT.equals(algorithm)) {
+ return null;
}
+ return initializer.newInstance(algorithm.getClazz());
}
private void hashPasswordForNewAlgorithm(String password, String playerName) {
diff --git a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java
index a114adc0..67d8c794 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java
@@ -9,13 +9,15 @@ import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.util.StringUtils;
+import javax.inject.Inject;
@Recommendation(Usage.RECOMMENDED) // provided the salt length is >= 8
-@HasSalt(value = SaltType.TEXT) // length depends on Settings.bCryptLog2Rounds
+@HasSalt(value = SaltType.TEXT) // length depends on the bcryptLog2Rounds setting
public class BCRYPT implements EncryptionMethod {
private final int bCryptLog2Rounds;
+ @Inject
public BCRYPT(NewSetting settings) {
this.bCryptLog2Rounds = settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND);
}
diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java
index 27066f7a..bf67432b 100644
--- a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java
+++ b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java
@@ -8,14 +8,17 @@ import fr.xephi.authme.security.crypts.description.Usage;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.SecuritySettings;
+import javax.inject.Inject;
+
import static fr.xephi.authme.security.HashUtils.md5;
@Recommendation(Usage.ACCEPTABLE) // presuming that length is something sensible (>= 8)
-@HasSalt(value = SaltType.TEXT) // length defined by Settings.saltLength
+@HasSalt(value = SaltType.TEXT) // length defined by the doubleMd5SaltLength setting
public class SALTED2MD5 extends SeparateSaltMethod {
private final int saltLength;
+ @Inject
public SALTED2MD5(NewSetting settings) {
saltLength = settings.getProperty(SecuritySettings.DOUBLE_MD5_SALT_LENGTH);
}
diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java
index 59693a98..a046d813 100644
--- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java
+++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java
@@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.hooks.PluginHooks;
+import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.FileUtils;
import fr.xephi.authme.util.StringUtils;
@@ -14,6 +15,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
+import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
@@ -40,7 +42,8 @@ public class SpawnLoader {
* @param settings The setting instance
* @param pluginHooks The plugin hooks instance
*/
- public SpawnLoader(File pluginFolder, NewSetting settings, PluginHooks pluginHooks) {
+ @Inject
+ public SpawnLoader(@DataFolder File pluginFolder, NewSetting settings, PluginHooks pluginHooks) {
File spawnFile = new File(pluginFolder, "spawn.yml");
// TODO ljacqu 20160312: Check if resource could be copied and handle the case if not
FileUtils.copyFileFromResource(spawnFile, "spawn.yml");
diff --git a/src/main/java/fr/xephi/authme/util/BukkitService.java b/src/main/java/fr/xephi/authme/util/BukkitService.java
index ea405d80..592caa22 100644
--- a/src/main/java/fr/xephi/authme/util/BukkitService.java
+++ b/src/main/java/fr/xephi/authme/util/BukkitService.java
@@ -7,6 +7,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
+import javax.inject.Inject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
@@ -28,6 +29,7 @@ public class BukkitService {
private final boolean getOnlinePlayersIsCollection;
private Method getOnlinePlayers;
+ @Inject
public BukkitService(AuthMe authMe) {
this.authMe = authMe;
getOnlinePlayersIsCollection = initializeOnlinePlayersIsCollectionField();
diff --git a/src/main/java/fr/xephi/authme/util/Utils.java b/src/main/java/fr/xephi/authme/util/Utils.java
index 5850645b..5d8c08ee 100644
--- a/src/main/java/fr/xephi/authme/util/Utils.java
+++ b/src/main/java/fr/xephi/authme/util/Utils.java
@@ -165,8 +165,9 @@ public final class Utils {
});
}
+ @Deprecated
public static boolean isNPC(Player player) {
- return player.hasMetadata("NPC") || plugin.getPluginHooks().isNpcInCombatTagPlus(player);
+ return plugin.getPluginHooks().isNpc(player);
}
public static void teleportToSpawn(Player player) {
diff --git a/src/main/java/fr/xephi/authme/util/ValidationService.java b/src/main/java/fr/xephi/authme/util/ValidationService.java
index 95dff810..999e2d1c 100644
--- a/src/main/java/fr/xephi/authme/util/ValidationService.java
+++ b/src/main/java/fr/xephi/authme/util/ValidationService.java
@@ -12,6 +12,7 @@ import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.command.CommandSender;
+import javax.inject.Inject;
import java.util.Collection;
import java.util.List;
@@ -24,6 +25,7 @@ public class ValidationService {
private final DataSource dataSource;
private final PermissionsManager permissionsManager;
+ @Inject
public ValidationService(NewSetting settings, DataSource dataSource, PermissionsManager permissionsManager) {
this.settings = settings;
this.dataSource = dataSource;
diff --git a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java
index 6e5418d5..7c62377f 100644
--- a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java
+++ b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java
@@ -1,10 +1,13 @@
package fr.xephi.authme.command;
+import fr.xephi.authme.initialization.AuthMeServiceInitializer;
import fr.xephi.authme.permission.AdminPermission;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.util.StringUtils;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import java.util.ArrayList;
import java.util.Collection;
@@ -21,6 +24,9 @@ import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
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.
@@ -37,7 +43,16 @@ public class CommandInitializerTest {
@BeforeClass
public static void initializeCommandManager() {
- commands = CommandInitializer.buildCommands();
+ AuthMeServiceInitializer initializer = mock(AuthMeServiceInitializer.class);
+ when(initializer.newInstance(any(Class.class))).thenAnswer(new Answer