diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java index 46e095bc88..298c972455 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -210,7 +210,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable { } } } - craftThreadManager.interruptTask(plugin); + craftThreadManager.interruptTasks(plugin); } public void cancelAllTasks() { @@ -220,4 +220,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable { craftThreadManager.interruptAllTasks(); } + public boolean isCurrentlyRunning(int taskId){ + return craftThreadManager.isAlive(taskId); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java index 80a1e78557..7d5b610e96 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java @@ -4,7 +4,7 @@ import java.lang.Comparable; import org.bukkit.plugin.Plugin; -public class CraftTask implements Comparable { +public class CraftTask implements Comparable { private final Runnable task; private final boolean syncTask; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java index 8ded4984c5..d63b458e43 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java @@ -1,7 +1,6 @@ package org.bukkit.craftbukkit.scheduler; import java.util.HashSet; -import java.util.LinkedList; import java.util.Iterator; import org.bukkit.plugin.Plugin; @@ -31,7 +30,7 @@ public class CraftThreadManager { } } - void interruptTask(Plugin owner) { + void interruptTasks(Plugin owner) { synchronized (workers) { Iterator itr = workers.iterator(); while (itr.hasNext()) { @@ -52,4 +51,18 @@ public class CraftThreadManager { } } } + + boolean isAlive(int taskId) { + synchronized (workers) { + Iterator itr = workers.iterator(); + while (itr.hasNext()) { + CraftWorker craftWorker = itr.next(); + if (craftWorker.getTaskId() == taskId) { + return craftWorker.isAlive(); + } + } + } + // didn't find it, so it must have been removed + return false; + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java index 2bb9400dfe..3bf91e4fbf 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftWorker.java @@ -53,6 +53,10 @@ public class CraftWorker implements Runnable { t.interrupt(); } + public boolean isAlive() { + return t.isAlive(); + } + private static int getNextHashId() { synchronized (hashIdCounterSync) { return hashIdCounter++;