mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-11-01 08:39:31 +01:00
Wrap Folia scheduler in the same check as Bukkit scheduler to ensure tasks running at disable don't get sent to the scheduler
This commit is contained in:
parent
6d744ccec4
commit
c8590cfe2f
@ -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<Server, Plugin> 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<Server, Plugin> runNormal) {
|
||||
runNormal.accept(discordSRV.server(), discordSRV.plugin());
|
||||
|
@ -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<Server, Plugin> 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));
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user