diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/AbstractBukkitScheduler.java b/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/AbstractBukkitScheduler.java index f70cca97..cce64723 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/AbstractBukkitScheduler.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/AbstractBukkitScheduler.java @@ -19,6 +19,8 @@ package com.discordsrv.bukkit.scheduler; import com.discordsrv.bukkit.BukkitDiscordSRV; +import com.discordsrv.bukkit.DiscordSRVBukkitBootstrap; +import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.scheduler.ServerScheduler; import com.discordsrv.common.scheduler.StandardScheduler; import org.bukkit.Server; @@ -35,6 +37,16 @@ public abstract class AbstractBukkitScheduler extends StandardScheduler implemen this.discordSRV = discordSRV; } + protected void checkDisable(Runnable task, BiConsumer runNormal) { + // Can't run tasks when disabling, so we'll push those to the bootstrap to run after disable + if (!discordSRV.plugin().isEnabled() && discordSRV.status() == DiscordSRV.Status.SHUTTING_DOWN) { + ((DiscordSRVBukkitBootstrap) discordSRV.bootstrap()).mainThreadTasksForDisable().add(task); + return; + } + + runWithArgs(runNormal); + } + @Override public void runWithArgs(BiConsumer runNormal) { runNormal.accept(discordSRV.server(), discordSRV.plugin()); diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/BukkitScheduler.java b/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/BukkitScheduler.java index 746911c4..f543a1b2 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/BukkitScheduler.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/BukkitScheduler.java @@ -19,12 +19,6 @@ package com.discordsrv.bukkit.scheduler; import com.discordsrv.bukkit.BukkitDiscordSRV; -import com.discordsrv.bukkit.DiscordSRVBukkitBootstrap; -import com.discordsrv.common.DiscordSRV; -import org.bukkit.Server; -import org.bukkit.plugin.Plugin; - -import java.util.function.BiConsumer; public class BukkitScheduler extends AbstractBukkitScheduler { @@ -32,16 +26,6 @@ public class BukkitScheduler extends AbstractBukkitScheduler { super(discordSRV); } - protected void checkDisable(Runnable task, BiConsumer runNormal) { - // Can't run tasks when disabling, so we'll push those to the bootstrap to run after disable - if (!discordSRV.plugin().isEnabled() && discordSRV.status() == DiscordSRV.Status.SHUTTING_DOWN) { - ((DiscordSRVBukkitBootstrap) discordSRV.bootstrap()).mainThreadTasksForDisable().add(task); - return; - } - - runWithArgs(runNormal); - } - @Override public void runOnMainThread(Runnable task) { checkDisable(task, (server, plugin) -> server.getScheduler().runTask(plugin, task)); diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/FoliaScheduler.java b/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/FoliaScheduler.java index eb12f3ce..550b65f4 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/FoliaScheduler.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/scheduler/FoliaScheduler.java @@ -25,4 +25,19 @@ public class FoliaScheduler extends AbstractBukkitScheduler implements IFoliaSch public FoliaScheduler(BukkitDiscordSRV discordSRV) { super(discordSRV); } + + @Override + public void runOnMainThread(Runnable task) { + checkDisable(task, (server, plugin) -> IFoliaScheduler.super.runOnMainThread(task)); + } + + @Override + public void runOnMainThreadLaterInTicks(Runnable task, int ticks) { + checkDisable(task, (server, plugin) -> IFoliaScheduler.super.runOnMainThreadLaterInTicks(task, ticks)); + } + + @Override + public void runOnMainThreadAtFixedRateInTicks(Runnable task, int initialTicks, int rateTicks) { + checkDisable(task, (server, plugin) -> IFoliaScheduler.super.runOnMainThreadAtFixedRateInTicks(task, initialTicks, rateTicks)); + } }