mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 01:00:18 +01:00
Run auto purge task asynchronously.
* prevent blocking server startup.
This commit is contained in:
parent
6f8b970c5c
commit
79eb0248f8
@ -138,6 +138,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
private PluginHooks pluginHooks;
|
private PluginHooks pluginHooks;
|
||||||
private SpawnLoader spawnLoader;
|
private SpawnLoader spawnLoader;
|
||||||
private AntiBot antiBot;
|
private AntiBot antiBot;
|
||||||
|
private boolean autoPurging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the plugin's instance.
|
* Get the plugin's instance.
|
||||||
@ -309,10 +310,6 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
// Register event listeners
|
// Register event listeners
|
||||||
registerEventListeners(messages, database, management, pluginHooks, spawnLoader, antiBot);
|
registerEventListeners(messages, database, management, pluginHooks, spawnLoader, antiBot);
|
||||||
|
|
||||||
// Purge on start if enabled
|
|
||||||
autoPurge();
|
|
||||||
|
|
||||||
// Start Email recall task if needed
|
// Start Email recall task if needed
|
||||||
scheduleRecallEmailTask();
|
scheduleRecallEmailTask();
|
||||||
|
|
||||||
@ -326,6 +323,9 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
// Successful message
|
// Successful message
|
||||||
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!");
|
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!");
|
||||||
|
|
||||||
|
// Purge on start if enabled
|
||||||
|
runAutoPurge();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -565,9 +565,9 @@ public class AuthMe extends JavaPlugin {
|
|||||||
*
|
*
|
||||||
* @param settings The settings instance
|
* @param settings The settings instance
|
||||||
*
|
*
|
||||||
* @see AuthMe#database
|
|
||||||
* @throws ClassNotFoundException if no driver could be found for the datasource
|
* @throws ClassNotFoundException if no driver could be found for the datasource
|
||||||
* @throws SQLException when initialization of a SQL datasource failed
|
* @throws SQLException when initialization of a SQL datasource failed
|
||||||
|
* @see AuthMe#database
|
||||||
*/
|
*/
|
||||||
public void setupDatabase(NewSetting settings) throws ClassNotFoundException, SQLException {
|
public void setupDatabase(NewSetting settings) throws ClassNotFoundException, SQLException {
|
||||||
if (this.database != null) {
|
if (this.database != null) {
|
||||||
@ -711,28 +711,37 @@ public class AuthMe extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Purge inactive players from the database, as defined in the configuration
|
// Purge inactive players from the database, as defined in the configuration
|
||||||
private void autoPurge() {
|
private void runAutoPurge() {
|
||||||
if (!newSettings.getProperty(PurgeSettings.USE_AUTO_PURGE)) {
|
if (!newSettings.getProperty(PurgeSettings.USE_AUTO_PURGE) || autoPurging) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Calendar calendar = Calendar.getInstance();
|
autoPurging = true;
|
||||||
calendar.add(Calendar.DATE, -newSettings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER));
|
server.getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||||
long until = calendar.getTimeInMillis();
|
@Override
|
||||||
List<String> cleared = database.autoPurgeDatabase(until);
|
public void run() {
|
||||||
if (CollectionUtils.isEmpty(cleared)) {
|
ConsoleLogger.info("AutoPurging the Database...");
|
||||||
return;
|
Calendar calendar = Calendar.getInstance();
|
||||||
}
|
calendar.add(Calendar.DATE, -newSettings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER));
|
||||||
ConsoleLogger.info("AutoPurging the Database: " + cleared.size() + " accounts removed!");
|
long until = calendar.getTimeInMillis();
|
||||||
if (newSettings.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) && pluginHooks.isEssentialsAvailable())
|
List<String> cleared = database.autoPurgeDatabase(until);
|
||||||
dataManager.purgeEssentials(cleared);
|
if (CollectionUtils.isEmpty(cleared)) {
|
||||||
if (newSettings.getProperty(PurgeSettings.REMOVE_PLAYER_DAT))
|
return;
|
||||||
dataManager.purgeDat(cleared);
|
}
|
||||||
if (newSettings.getProperty(PurgeSettings.REMOVE_LIMITED_CREATIVE_INVENTORIES))
|
ConsoleLogger.info("AutoPurging the Database: " + cleared.size() + " accounts removed!");
|
||||||
dataManager.purgeLimitedCreative(cleared);
|
if (newSettings.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) && pluginHooks.isEssentialsAvailable())
|
||||||
if (newSettings.getProperty(PurgeSettings.REMOVE_ANTI_XRAY_FILE))
|
dataManager.purgeEssentials(cleared);
|
||||||
dataManager.purgeAntiXray(cleared);
|
if (newSettings.getProperty(PurgeSettings.REMOVE_PLAYER_DAT))
|
||||||
if (newSettings.getProperty(PurgeSettings.REMOVE_PERMISSIONS))
|
dataManager.purgeDat(cleared);
|
||||||
dataManager.purgePermissions(cleared);
|
if (newSettings.getProperty(PurgeSettings.REMOVE_LIMITED_CREATIVE_INVENTORIES))
|
||||||
|
dataManager.purgeLimitedCreative(cleared);
|
||||||
|
if (newSettings.getProperty(PurgeSettings.REMOVE_ANTI_XRAY_FILE))
|
||||||
|
dataManager.purgeAntiXray(cleared);
|
||||||
|
if (newSettings.getProperty(PurgeSettings.REMOVE_PERMISSIONS))
|
||||||
|
dataManager.purgePermissions(cleared);
|
||||||
|
ConsoleLogger.info("AutoPurge Finished!");
|
||||||
|
autoPurging = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the spawn location of a player
|
// Return the spawn location of a player
|
||||||
|
Loading…
Reference in New Issue
Block a user