Check for update every 6 hours

This commit is contained in:
Andrew 2013-09-18 09:38:36 +12:00
parent fc6c34280c
commit a49f4d41ec

View File

@ -29,24 +29,27 @@ public class DisguiseListener implements Listener {
permission = plugin.getConfig().getString("Permission"); permission = plugin.getConfig().getString("Permission");
if (plugin.getConfig().getBoolean("NotifyUpdate")) { if (plugin.getConfig().getBoolean("NotifyUpdate")) {
currentVersion = plugin.getDescription().getVersion(); currentVersion = plugin.getDescription().getVersion();
Bukkit.getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() { Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
public void run() { public void run() {
try { try {
UpdateChecker updateChecker = new UpdateChecker(); UpdateChecker updateChecker = new UpdateChecker();
updateChecker.checkUpdate("v" updateChecker.checkUpdate("v" + currentVersion);
+ Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion());
latestVersion = updateChecker.getLatestVersion(); latestVersion = updateChecker.getLatestVersion();
if (latestVersion != null) { if (latestVersion != null) {
latestVersion = "v" + latestVersion; latestVersion = "v" + latestVersion;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
for (Player p : Bukkit.getOnlinePlayers()) for (Player p : Bukkit.getOnlinePlayers())
if (p.hasPermission(permission)) if (p.hasPermission(permission))
p.sendMessage(String.format(updateMessage, currentVersion, latestVersion)); p.sendMessage(String.format(updateMessage, currentVersion, latestVersion));
} }
});
}
} catch (Exception ex) { } catch (Exception ex) {
System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage())); System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage()));
} }
} }
}); }, 0, (20 * 60 * 60 * 6)); // Check every 6 hours
} }
} }