mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-27 12:45:57 +01:00
Apply minor changes to PurgeService
- Remove various imports / unused fields - Make CacheDataSource call source for purging on DB - Minor: SQLite - place creation of PreparedStatement outside of loop - Make specific purge actions called from task package-private (clearer from the outside which methods can be called from the outside)
This commit is contained in:
parent
fb8baeafd2
commit
2ac89f5938
@ -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)
|
||||
|
@ -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<String> arguments) {
|
||||
// Get the list of banned players
|
||||
Set<String> namedBanned = new HashSet<>();
|
||||
Set<OfflinePlayer> bannedPlayers = bukkitService.getBannedPlayers();
|
||||
Set<String> namedBanned = new HashSet<>(bannedPlayers.size());
|
||||
for (OfflinePlayer offlinePlayer : bannedPlayers) {
|
||||
namedBanned.add(offlinePlayer.getName().toLowerCase());
|
||||
}
|
||||
|
@ -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<String> arguments) {
|
||||
// Get the days parameter
|
||||
|
@ -145,6 +145,7 @@ public class CacheDataSource implements DataSource {
|
||||
|
||||
@Override
|
||||
public void purgeRecords(Set<String> toPurge) {
|
||||
source.purgeRecords(toPurge);
|
||||
for (String name : toPurge) {
|
||||
cachedAuths.invalidate(name);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<String> cleared) {
|
||||
synchronized void purgeAntiXray(Set<String> 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<String> cleared) {
|
||||
synchronized void purgeLimitedCreative(Set<String> 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<OfflinePlayer> cleared) {
|
||||
synchronized void purgeDat(Set<OfflinePlayer> cleared) {
|
||||
if (!removePlayerDat) {
|
||||
return;
|
||||
}
|
||||
@ -254,7 +253,7 @@ public class PurgeService implements Reloadable {
|
||||
*
|
||||
* @param cleared List of String
|
||||
*/
|
||||
public synchronized void purgeEssentials(Set<OfflinePlayer> cleared) {
|
||||
synchronized void purgeEssentials(Set<OfflinePlayer> 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<OfflinePlayer> cleared) {
|
||||
synchronized void purgePermissions(Set<OfflinePlayer> cleared) {
|
||||
if (!removePermissions) {
|
||||
return;
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user