Run auto purge task asynchronously.

* prevent blocking server startup.
This commit is contained in:
DNx5 2016-04-01 08:33:11 +07:00
parent 6f8b970c5c
commit 79eb0248f8

View File

@ -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,10 +711,15 @@ 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;
} }
autoPurging = true;
server.getScheduler().runTaskAsynchronously(this, new Runnable() {
@Override
public void run() {
ConsoleLogger.info("AutoPurging the Database...");
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -newSettings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER)); calendar.add(Calendar.DATE, -newSettings.getProperty(PurgeSettings.DAYS_BEFORE_REMOVE_PLAYER));
long until = calendar.getTimeInMillis(); long until = calendar.getTimeInMillis();
@ -733,6 +738,10 @@ public class AuthMe extends JavaPlugin {
dataManager.purgeAntiXray(cleared); dataManager.purgeAntiXray(cleared);
if (newSettings.getProperty(PurgeSettings.REMOVE_PERMISSIONS)) if (newSettings.getProperty(PurgeSettings.REMOVE_PERMISSIONS))
dataManager.purgePermissions(cleared); dataManager.purgePermissions(cleared);
ConsoleLogger.info("AutoPurge Finished!");
autoPurging = false;
}
});
} }
// Return the spawn location of a player // Return the spawn location of a player