Skip to content

Commit

Permalink
use isQueued & isCurrentlyRunning if isCancelled is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Aug 18, 2023
1 parent 071a498 commit c789d17
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,18 @@ static BukkitRunnable wrapRunnable(Entity entity, Runnable runnable, Runnable re

static Task wrapTask(BukkitTask bukkitTask, boolean repeating) {
return new Task() {
boolean cancelled = false;

@Override
public boolean isCancelled() {
try {
return bukkitTask.isCancelled();
} catch (Throwable throwable) {
return cancelled; // For old versions that don't have isCancelled()
int taskId = bukkitTask.getTaskId();
return !(Bukkit.getScheduler().isQueued(taskId) || Bukkit.getScheduler().isCurrentlyRunning(taskId));
}
}

@Override
public void cancel() {
cancelled = true;
bukkitTask.cancel();
}

Expand Down

0 comments on commit c789d17

Please sign in to comment.