fix(folia,build): route teleports and timers through scheduler; unpin floodgate transitive

This commit is contained in:
Loki 2026-10-19 20:23:39 +02:00
parent b6712391fd
commit eed73b5c44
Signed by: boba
GPG key ID: 253067914055423B
15 changed files with 160 additions and 13 deletions

View file

@ -20,21 +20,27 @@ final class FoliaBackend implements Scheduler.Backend {
private static final String GLOBAL_SCHEDULER_CLASS = "GlobalRegionScheduler";
private static final String ASYNC_SCHEDULER_CLASS = "AsyncScheduler";
private static final String REGION_SCHEDULER_CLASS = "RegionScheduler";
private final Plugin plugin;
private final Object globalScheduler;
private final Object asyncScheduler;
private final Object regionScheduler;
private final Method globalRun;
private final Method globalRunDelayed;
private final Method globalRunAtFixedRate;
private final Method asyncRunNow;
private final Method asyncRunAtFixedRate;
private final Method regionRunDelayed;
private final Method regionRunAtFixedRate;
private final Method entityExecute;
private final Method taskCancel;
FoliaBackend(Plugin plugin) throws ReflectiveOperationException {
this.plugin = plugin;
this.globalScheduler = scheduler("getGlobalRegionScheduler");
this.asyncScheduler = scheduler("getAsyncScheduler");
this.regionScheduler = scheduler("getRegionScheduler");
this.globalRun = method(GLOBAL_SCHEDULER_CLASS, "run", Plugin.class, Consumer.class);
this.globalRunDelayed = method(GLOBAL_SCHEDULER_CLASS, "runDelayed",
Plugin.class, Consumer.class, long.class);
@ -43,6 +49,12 @@ final class FoliaBackend implements Scheduler.Backend {
this.asyncRunNow = method(ASYNC_SCHEDULER_CLASS, "runNow", Plugin.class, Consumer.class);
this.asyncRunAtFixedRate = method(ASYNC_SCHEDULER_CLASS, "runAtFixedRate",
Plugin.class, Consumer.class, long.class, long.class);
this.regionRunDelayed = method(REGION_SCHEDULER_CLASS, "runDelayed",
Plugin.class, org.bukkit.Location.class, Consumer.class, long.class);
this.regionRunAtFixedRate = method(REGION_SCHEDULER_CLASS, "runAtFixedRate",
Plugin.class, org.bukkit.Location.class, Consumer.class, long.class, long.class);
this.entityExecute = Class.forName(SCHEDULER_PACKAGE + "EntityScheduler")
.getMethod("execute", Plugin.class, Runnable.class);
this.taskCancel = Class.forName(SCHEDULER_PACKAGE + "ScheduledTask").getMethod("cancel");
}
@ -67,6 +79,29 @@ final class FoliaBackend implements Scheduler.Backend {
consumer(task), delayTicks, periodTicks));
}
@Override
public ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location,
long delayTicks, long periodTicks) {
return wrap(invoke(regionRunAtFixedRate, regionScheduler, plugin, location,
consumer(task), delayTicks, periodTicks));
}
@Override
public ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks) {
return wrap(invoke(regionRunDelayed, regionScheduler, plugin, location,
consumer(task), delayTicks));
}
@Override
public ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity) {
try {
final Object entityScheduler = entity.getClass().getMethod("getScheduler").invoke(entity);
return wrap(invoke(entityExecute, entityScheduler, plugin, task));
} catch (ReflectiveOperationException | IllegalArgumentException cause) {
throw new IllegalStateException("Folia entity scheduler call failed", cause);
}
}
@Override
public ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks) {
return wrap(invoke(asyncRunAtFixedRate, asyncScheduler, plugin,