diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 486c474eb..d9f9bd879 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -36,7 +36,7 @@ import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PermissionsSystemType; import fr.xephi.authme.process.Management; -import fr.xephi.authme.process.purge.PurgeService; +import fr.xephi.authme.task.PurgeService; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.SHA256; import fr.xephi.authme.settings.NewSetting; @@ -47,14 +47,11 @@ import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; -import fr.xephi.authme.settings.properties.PurgeSettings; import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SettingsFieldRetriever; import fr.xephi.authme.settings.propertymap.PropertyMap; -import fr.xephi.authme.task.PurgeTask; import fr.xephi.authme.util.BukkitService; -import fr.xephi.authme.util.CollectionUtils; import fr.xephi.authme.util.FileUtils; import fr.xephi.authme.util.GeoLiteAPI; import fr.xephi.authme.util.MigrationService; @@ -75,11 +72,9 @@ import org.bukkit.scheduler.BukkitTask; import java.io.File; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.List; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; @@ -131,10 +126,8 @@ public class AuthMe extends JavaPlugin { private DataSource database; private PluginHooks pluginHooks; private SpawnLoader spawnLoader; - private boolean autoPurging; private BukkitService bukkitService; private AuthMeServiceInitializer initializer; - private PurgeService purgeService; /** * Get the plugin's instance. @@ -257,7 +250,6 @@ public class AuthMe extends JavaPlugin { api = initializer.get(NewAPI.class); management = initializer.get(Management.class); dataManager = initializer.get(DataManager.class); - purgeService = initializer.get(PurgeService.class); initializer.get(API.class); // Set up Metrics @@ -313,6 +305,7 @@ public class AuthMe extends JavaPlugin { } // Purge on start if enabled + PurgeService purgeService = initializer.get(PurgeService.class); purgeService.runAutoPurge(); } @@ -714,10 +707,6 @@ public class AuthMe extends JavaPlugin { return commandHandler.processCommand(sender, commandLabel, args); } - public void notifyAutoPurgeEnd() { - this.autoPurging = false; - } - // ------------- // Service getters (deprecated) 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 28c5e5ff0..b298fd17a 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 @@ -1,12 +1,8 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.AuthMe; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.process.purge.PurgeService; -import fr.xephi.authme.task.PurgeTask; +import fr.xephi.authme.task.PurgeService; import fr.xephi.authme.util.BukkitService; -import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -30,8 +26,8 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand { @Override public void executeCommand(CommandSender sender, List arguments) { // Get the list of banned players - Set namedBanned = new HashSet<>(); Set bannedPlayers = bukkitService.getBannedPlayers(); + Set namedBanned = new HashSet<>(bannedPlayers.size()); for (OfflinePlayer offlinePlayer : bannedPlayers) { namedBanned.add(offlinePlayer.getName().toLowerCase()); } 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 99814566d..1885dc76c 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 @@ -1,17 +1,13 @@ package fr.xephi.authme.command.executable.authme; -import fr.xephi.authme.AuthMe; import fr.xephi.authme.command.ExecutableCommand; -import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.process.purge.PurgeService; -import fr.xephi.authme.task.PurgeTask; +import fr.xephi.authme.task.PurgeService; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import javax.inject.Inject; import java.util.Calendar; import java.util.List; -import java.util.Set; /** * Command for purging the data of players which have not been since for a given number @@ -24,9 +20,6 @@ public class PurgeCommand implements ExecutableCommand { @Inject private PurgeService purgeService; - @Inject - private AuthMe plugin; - @Override public void executeCommand(CommandSender sender, List arguments) { // Get the days parameter diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 50c613511..547110e40 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -145,6 +145,7 @@ public class CacheDataSource implements DataSource { @Override public void purgeRecords(Set toPurge) { + source.purgeRecords(toPurge); for (String name : toPurge) { cachedAuths.invalidate(name); } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 5464e0cb4..dc15bcb9a 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -8,7 +8,6 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.settings.Settings; -import javax.swing.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 7a0a5c8d0..fa8ddedda 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -1,5 +1,14 @@ package fr.xephi.authme.datasource; +import com.google.common.annotations.VisibleForTesting; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.security.crypts.HashedPassword; +import fr.xephi.authme.settings.NewSetting; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.properties.DatabaseSettings; +import fr.xephi.authme.util.StringUtils; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -11,16 +20,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import com.google.common.annotations.VisibleForTesting; - -import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.cache.auth.PlayerAuth; -import fr.xephi.authme.security.crypts.HashedPassword; -import fr.xephi.authme.settings.NewSetting; -import fr.xephi.authme.settings.Settings; -import fr.xephi.authme.settings.properties.DatabaseSettings; -import fr.xephi.authme.util.StringUtils; - /** */ public class SQLite implements DataSource { @@ -314,13 +313,13 @@ public class SQLite implements DataSource { @Override public void purgeRecords(Set toPurge) { String delete = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;"; - for (String name : toPurge) { - try (PreparedStatement deletePst = con.prepareStatement(delete)) { + try (PreparedStatement deletePst = con.prepareStatement(delete)) { + for (String name : toPurge) { deletePst.setString(1, name); deletePst.executeUpdate(); - } catch (SQLException ex) { - logSqlException(ex); } + } catch (SQLException ex) { + logSqlException(ex); } } diff --git a/src/main/java/fr/xephi/authme/permission/handlers/GroupManagerHandler.java b/src/main/java/fr/xephi/authme/permission/handlers/GroupManagerHandler.java index 475fafee0..383f109bb 100644 --- a/src/main/java/fr/xephi/authme/permission/handlers/GroupManagerHandler.java +++ b/src/main/java/fr/xephi/authme/permission/handlers/GroupManagerHandler.java @@ -3,7 +3,6 @@ package fr.xephi.authme.permission.handlers; import fr.xephi.authme.permission.PermissionNode; import fr.xephi.authme.permission.PermissionsSystemType; import org.anjocaido.groupmanager.GroupManager; -import org.anjocaido.groupmanager.data.User; import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/src/main/java/fr/xephi/authme/process/purge/PurgeService.java b/src/main/java/fr/xephi/authme/task/PurgeService.java similarity index 95% rename from src/main/java/fr/xephi/authme/process/purge/PurgeService.java rename to src/main/java/fr/xephi/authme/task/PurgeService.java index 6970a5baa..b577e4e5a 100644 --- a/src/main/java/fr/xephi/authme/process/purge/PurgeService.java +++ b/src/main/java/fr/xephi/authme/task/PurgeService.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.process.purge; +package fr.xephi.authme.task; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSource; @@ -8,7 +8,6 @@ import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.properties.PurgeSettings; -import fr.xephi.authme.task.PurgeTask; import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.CollectionUtils; import fr.xephi.authme.util.Utils; @@ -72,7 +71,7 @@ public class PurgeService implements Reloadable { * * @param autoPurging True if automatically purging. */ - public void setAutoPurging(boolean autoPurging) { + void setAutoPurging(boolean autoPurging) { this.autoPurging = autoPurging; } @@ -165,7 +164,7 @@ public class PurgeService implements Reloadable { return toPurge; } - public synchronized void purgeAntiXray(Set cleared) { + synchronized void purgeAntiXray(Set cleared) { if (!removeAntiXrayFiles) { return; } @@ -189,7 +188,7 @@ public class PurgeService implements Reloadable { ConsoleLogger.info("AutoPurge: Removed " + i + " AntiXRayData Files"); } - public synchronized void purgeLimitedCreative(Set cleared) { + synchronized void purgeLimitedCreative(Set cleared) { if (!removeLimitedCreativeInventories) { return; } @@ -230,7 +229,7 @@ public class PurgeService implements Reloadable { ConsoleLogger.info("AutoPurge: Removed " + i + " LimitedCreative Survival, Creative and Adventure files"); } - public synchronized void purgeDat(Set cleared) { + synchronized void purgeDat(Set cleared) { if (!removePlayerDat) { return; } @@ -254,7 +253,7 @@ public class PurgeService implements Reloadable { * * @param cleared List of String */ - public synchronized void purgeEssentials(Set cleared) { + synchronized void purgeEssentials(Set cleared) { if (!removeEssentialsFiles && !pluginHooks.isEssentialsAvailable()) { return; } @@ -283,7 +282,7 @@ public class PurgeService implements Reloadable { // TODO: What is this method for? Is it correct? // TODO: Make it work with OfflinePlayers group data. - public synchronized void purgePermissions(Set cleared) { + synchronized void purgePermissions(Set cleared) { if (!removePermissions) { return; } diff --git a/src/main/java/fr/xephi/authme/task/PurgeTask.java b/src/main/java/fr/xephi/authme/task/PurgeTask.java index 983f48f2c..edfb1b505 100644 --- a/src/main/java/fr/xephi/authme/task/PurgeTask.java +++ b/src/main/java/fr/xephi/authme/task/PurgeTask.java @@ -1,12 +1,6 @@ package fr.xephi.authme.task; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.process.purge.PurgeService; - -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; @@ -14,6 +8,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + public class PurgeTask extends BukkitRunnable { private PurgeService purgeService;