mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-16 08:57:59 +02: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 SpawnLoader spawnLoader;
|
||||
private AntiBot antiBot;
|
||||
private boolean autoPurging;
|
||||
|
||||
/**
|
||||
* Get the plugin's instance.
|
||||
@ -309,10 +310,6 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Register event listeners
|
||||
registerEventListeners(messages, database, management, pluginHooks, spawnLoader, antiBot);
|
||||
|
||||
// Purge on start if enabled
|
||||
autoPurge();
|
||||
|
||||
// Start Email recall task if needed
|
||||
scheduleRecallEmailTask();
|
||||
|
||||
@ -326,6 +323,9 @@ public class AuthMe extends JavaPlugin {
|
||||
|
||||
// Successful message
|
||||
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
|
||||
*
|
||||
* @see AuthMe#database
|
||||
* @throws ClassNotFoundException if no driver could be found for the datasource
|
||||
* @throws SQLException when initialization of a SQL datasource failed
|
||||
* @see AuthMe#database
|
||||
*/
|
||||
public void setupDatabase(NewSetting settings) throws ClassNotFoundException, SQLException {
|
||||
if (this.database != null) {
|
||||
@ -711,10 +711,15 @@ public class AuthMe extends JavaPlugin {
|
||||
}
|
||||
|
||||
// Purge inactive players from the database, as defined in the configuration
|
||||
private void autoPurge() {
|
||||
if (!newSettings.getProperty(PurgeSettings.USE_AUTO_PURGE)) {
|
||||
private void runAutoPurge() {
|
||||
if (!newSettings.getProperty(PurgeSettings.USE_AUTO_PURGE) || autoPurging) {
|
||||
return;
|
||||
}
|
||||
autoPurging = true;
|
||||
server.getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ConsoleLogger.info("AutoPurging the Database...");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.DATE, -newSettings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER));
|
||||
long until = calendar.getTimeInMillis();
|
||||
@ -733,6 +738,10 @@ public class AuthMe extends JavaPlugin {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user