From a4a1ba43318a0757816fc57010922d0002dbcac9 Mon Sep 17 00:00:00 2001 From: riking Date: Thu, 27 Jun 2013 09:31:06 -0700 Subject: [PATCH] Make UpdateChecker run asynchronously and not block startup Closes #1049 --- src/main/java/com/gmail/nossr50/mcMMO.java | 12 +++++------- .../nossr50/runnables/UpdateCheckerTask.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/runnables/UpdateCheckerTask.java diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index aba9d00e7..c197d1faa 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -35,6 +35,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.metrics.MetricsManager; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.runnables.SaveTimerTask; +import com.gmail.nossr50.runnables.UpdateCheckerTask; import com.gmail.nossr50.runnables.database.UserPurgeTask; import com.gmail.nossr50.runnables.party.PartyAutoKickTask; 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.Misc; 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.ChunkManagerFactory; import com.gmail.nossr50.util.commands.CommandRegistrationManager; @@ -266,13 +266,11 @@ public class mcMMO extends JavaPlugin { return; } - try { - updateAvailable = UpdateChecker.updateAvailable(); - } - catch (Exception e) { - updateAvailable = false; - } + getServer().getScheduler().runTaskAsynchronously(this, new UpdateCheckerTask()); + } + public void updateCheckerCallback(boolean updateAvailable) { + this.updateAvailable = updateAvailable; if (updateAvailable) { getLogger().info(LocaleLoader.getString("UpdateChecker.outdated")); getLogger().info(LocaleLoader.getString("UpdateChecker.newavailable")); diff --git a/src/main/java/com/gmail/nossr50/runnables/UpdateCheckerTask.java b/src/main/java/com/gmail/nossr50/runnables/UpdateCheckerTask.java new file mode 100644 index 000000000..20d88d498 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/UpdateCheckerTask.java @@ -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); + } + } +}