Merge pull request #668 from CocoTheOwner/noTaskIfDisabled

Prevent scheduling tasks while disabled
This commit is contained in:
Dan 2021-11-11 17:55:53 -05:00 committed by GitHub
commit 8be08acfa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,6 +27,7 @@ import com.volmit.iris.util.function.NastySupplier;
import com.volmit.iris.util.math.FinalInteger; import com.volmit.iris.util.math.FinalInteger;
import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.parallel.MultiBurst;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.IllegalPluginAccessException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -88,6 +89,9 @@ public class J {
} }
public static void aBukkit(Runnable a) { public static void aBukkit(Runnable a) {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return;
}
Bukkit.getScheduler().scheduleAsyncDelayedTask(Iris.instance, a); Bukkit.getScheduler().scheduleAsyncDelayedTask(Iris.instance, a);
} }
@ -218,11 +222,18 @@ public class J {
* @param r the runnable * @param r the runnable
*/ */
public static void s(Runnable r) { public static void s(Runnable r) {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r); Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r);
} }
public static CompletableFuture sfut(Runnable r) { public static CompletableFuture sfut(Runnable r) {
CompletableFuture f = new CompletableFuture(); CompletableFuture f = new CompletableFuture();
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return null;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> {
r.run(); r.run();
f.complete(null); f.complete(null);
@ -232,6 +243,10 @@ public class J {
public static CompletableFuture sfut(Runnable r, int delay) { public static CompletableFuture sfut(Runnable r, int delay) {
CompletableFuture f = new CompletableFuture(); CompletableFuture f = new CompletableFuture();
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return null;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> { Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> {
r.run(); r.run();
f.complete(null); f.complete(null);
@ -256,6 +271,9 @@ public class J {
*/ */
public static void s(Runnable r, int delay) { public static void s(Runnable r, int delay) {
try { try {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return;
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r, delay); Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r, delay);
} catch (Throwable e) { } catch (Throwable e) {
Iris.reportError(e); Iris.reportError(e);
@ -279,6 +297,9 @@ public class J {
* @return the task id * @return the task id
*/ */
public static int sr(Runnable r, int interval) { public static int sr(Runnable r, int interval) {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return -1;
}
return Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, r, 0, interval); return Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, r, 0, interval);
} }
@ -313,8 +334,10 @@ public class J {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void a(Runnable r, int delay) { public static void a(Runnable r, int delay) {
if (Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
Bukkit.getScheduler().scheduleAsyncDelayedTask(Iris.instance, r, delay); Bukkit.getScheduler().scheduleAsyncDelayedTask(Iris.instance, r, delay);
} }
}
/** /**
* Cancel an async repeat task * Cancel an async repeat task
@ -334,6 +357,9 @@ public class J {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static int ar(Runnable r, int interval) { public static int ar(Runnable r, int interval) {
if (!Bukkit.getPluginManager().isPluginEnabled(Iris.instance)) {
return -1;
}
return Bukkit.getScheduler().scheduleAsyncRepeatingTask(Iris.instance, r, 0, interval); return Bukkit.getScheduler().scheduleAsyncRepeatingTask(Iris.instance, r, 0, interval);
} }