#432 Inject in commands: DataSource / AntiBot / PasswordSecurity / PlayerCache
- Inject the services instead of passing them through the command service
This commit is contained in:
+15
-5
@@ -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<String> 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)) {
|
||||
|
||||
@@ -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<String> 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 {
|
||||
|
||||
@@ -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<String> 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;
|
||||
|
||||
+7
-2
@@ -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<String> arguments, CommandService commandService) {
|
||||
// AuthMe plugin instance
|
||||
@@ -23,12 +28,12 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
|
||||
// Get the list of banned players
|
||||
List<String> 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);
|
||||
|
||||
@@ -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<String> 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<String> purged = commandService.getDataSource().autoPurgeDatabase(until);
|
||||
List<String> purged = dataSource.autoPurgeDatabase(until);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||
|
||||
+9
-4
@@ -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<String> 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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,14 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -16,6 +19,12 @@ import java.util.List;
|
||||
*/
|
||||
public class RegisterAdminCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments,
|
||||
final CommandService commandService) {
|
||||
@@ -35,23 +44,22 @@ 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);
|
||||
|
||||
@@ -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<String> 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
|
||||
|
||||
@@ -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<String> arguments, CommandService commandService) {
|
||||
AntiBot antiBot = commandService.getAntiBot();
|
||||
if (arguments.isEmpty()) {
|
||||
sender.sendMessage("[AuthMe] AntiBot status: " + antiBot.getAntiBotStatus().name());
|
||||
return;
|
||||
|
||||
+11
-3
@@ -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<String> 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)) {
|
||||
|
||||
+4
-1
@@ -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<String> 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;
|
||||
|
||||
@@ -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<String> 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 {
|
||||
|
||||
Reference in New Issue
Block a user