Make UpdateChecker run asynchronously and not block startup

Closes #1049
This commit is contained in:
riking 2013-06-27 09:31:06 -07:00
parent de46277bea
commit a4a1ba4331
2 changed files with 24 additions and 7 deletions

View File

@ -35,6 +35,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.metrics.MetricsManager; import com.gmail.nossr50.metrics.MetricsManager;
import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.SaveTimerTask; import com.gmail.nossr50.runnables.SaveTimerTask;
import com.gmail.nossr50.runnables.UpdateCheckerTask;
import com.gmail.nossr50.runnables.database.UserPurgeTask; import com.gmail.nossr50.runnables.database.UserPurgeTask;
import com.gmail.nossr50.runnables.party.PartyAutoKickTask; import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
@ -47,7 +48,6 @@ import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.LogFilter; import com.gmail.nossr50.util.LogFilter;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.UpdateChecker;
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager; import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManager;
import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory; import com.gmail.nossr50.util.blockmeta.chunkmeta.ChunkManagerFactory;
import com.gmail.nossr50.util.commands.CommandRegistrationManager; import com.gmail.nossr50.util.commands.CommandRegistrationManager;
@ -266,13 +266,11 @@ public class mcMMO extends JavaPlugin {
return; return;
} }
try { getServer().getScheduler().runTaskAsynchronously(this, new UpdateCheckerTask());
updateAvailable = UpdateChecker.updateAvailable(); }
}
catch (Exception e) {
updateAvailable = false;
}
public void updateCheckerCallback(boolean updateAvailable) {
this.updateAvailable = updateAvailable;
if (updateAvailable) { if (updateAvailable) {
getLogger().info(LocaleLoader.getString("UpdateChecker.outdated")); getLogger().info(LocaleLoader.getString("UpdateChecker.outdated"));
getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable")); getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable"));

View File

@ -0,0 +1,19 @@
package com.gmail.nossr50.runnables;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.UpdateChecker;
/**
* Async task
*/
public class UpdateCheckerTask implements Runnable {
@Override
public void run() {
try {
mcMMO.p.updateCheckerCallback(UpdateChecker.updateAvailable());
}
catch (Exception e) {
mcMMO.p.updateCheckerCallback(false);
}
}
}