When we reload the update checking, cancel the previous task.

This commit is contained in:
graywolf336 2014-07-21 18:23:31 -05:00
parent 70b2fbe1e1
commit bfd786f650

View File

@ -44,6 +44,7 @@ public class JailMain extends JavaPlugin {
private MoveProtectionListener mpl; private MoveProtectionListener mpl;
private Update update; private Update update;
private boolean debug = false; private boolean debug = false;
private int updateCheckTask = -1;
public void onEnable() { public void onEnable() {
loadConfig(); loadConfig();
@ -222,14 +223,15 @@ public class JailMain extends JavaPlugin {
} }
public void reloadUpdateCheck() { public void reloadUpdateCheck() {
getServer().getScheduler().cancelTask(updateCheckTask);
update = new Update(this); update = new Update(this);
if(getConfig().getBoolean(Settings.UPDATENOTIFICATIONS.getPath())) { if(getConfig().getBoolean(Settings.UPDATENOTIFICATIONS.getPath())) {
try { try {
getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() { updateCheckTask = getServer().getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
public void run() { public void run() {
update.query(); update.query();
} }
}, 80L, Util.getTime(getConfig().getString(Settings.UPDATETIME.getPath()), TimeUnit.SECONDS) * 20); }, 80L, Util.getTime(getConfig().getString(Settings.UPDATETIME.getPath()), TimeUnit.SECONDS) * 20).getTaskId();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
getLogger().severe("Was unable to schedule the update checking, please check your time format is correct."); getLogger().severe("Was unable to schedule the update checking, please check your time format is correct.");