From 972b4c1fe5f085a39bc5abb12f568a691ffa23fb Mon Sep 17 00:00:00 2001 From: Tux Date: Sun, 14 Dec 2014 00:02:29 -0500 Subject: [PATCH] Further fix task clean up issues by moving the BungeeScheduler's cancel(ScheduledTask) method to just call the cancel() method on the task. The cancel call was moved to BungeeTask's cancel method. This patch makes the patch transparent to existing callers using cancel(ScheduledTask) from the scheduler. It also simplifies some logic in BungeeTask itself. --- .../net/md_5/bungee/scheduler/BungeeScheduler.java | 2 +- .../java/net/md_5/bungee/scheduler/BungeeTask.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java index 418e9210..e3085db2 100644 --- a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java +++ b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeScheduler.java @@ -44,7 +44,7 @@ public class BungeeScheduler implements TaskScheduler @Override public void cancel(ScheduledTask task) { - cancel( task.getId() ); + task.cancel(); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java index 7e87ec13..195b50d4 100644 --- a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java +++ b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java @@ -34,7 +34,12 @@ public class BungeeTask implements Runnable, ScheduledTask @Override public void cancel() { - running.set( false ); + boolean wasRunning = running.getAndSet( false ); + + if ( wasRunning ) + { + sched.cancel( this.getId() ); + } } @Override @@ -76,11 +81,6 @@ public class BungeeTask implements Runnable, ScheduledTask } } - // We might have been previously running before, but now we aren't. - // If we weren't already cancelled, then cancel ourselves. - if ( running.get() ) - { - sched.cancel( this ); - } + cancel(); } }