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

@ -209,7 +209,9 @@ dependencies {
compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("me.clip:placeholderapi:2.11.6")
compileOnly("com.github.MilkBowl:VaultAPI:1.7") compileOnly("com.github.MilkBowl:VaultAPI:1.7")
compileOnly("me.filoghost.holographicdisplays:holographicdisplays-api:3.0.0-SNAPSHOT") compileOnly("me.filoghost.holographicdisplays:holographicdisplays-api:3.0.0-SNAPSHOT")
compileOnly("org.geysermc.floodgate:api:2.0-SNAPSHOT") // Only the API surface is needed; its transitive Geyser snapshot
// (org.geysermc:common:1.4.3-SNAPSHOT) was purged from every public repo.
compileOnly("org.geysermc.floodgate:api:2.0-SNAPSHOT") { isTransitive = false }
// Error Prone + NullAway (compile-time bug/null-safety checks) // Error Prone + NullAway (compile-time bug/null-safety checks)
errorprone("com.google.errorprone:error_prone_core:2.41.0") errorprone("com.google.errorprone:error_prone_core:2.41.0")
@ -245,7 +247,7 @@ tasks.named("build") {
} }
tasks.withType<ProcessResources> { tasks.withType<ProcessResources> {
filesMatching(listOf("plugin.yml", "config.yml")) { filesMatching(listOf("plugin.yml", "folia-plugin.yml", "config.yml")) {
expand( expand(
"version" to project.version, "version" to project.version,
"description" to (project.description ?: ""), "description" to (project.description ?: ""),

View file

@ -10,6 +10,7 @@ import dev.loki.loparkour.mode.base.Modes;
import dev.loki.loparkour.player.core.ParkourPlayer; import dev.loki.loparkour.player.core.ParkourPlayer;
import dev.loki.loparkour.scheduler.Scheduler; import dev.loki.loparkour.scheduler.Scheduler;
import dev.loki.loparkour.session.core.Session; import dev.loki.loparkour.session.core.Session;
import dev.loki.loparkour.util.misc.Compat;
import dev.loki.loparkour.util.text.ColorUtil; import dev.loki.loparkour.util.text.ColorUtil;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -113,7 +114,7 @@ public class DuelsGenerator extends ParkourGenerator {
final Location playerSpawn = platformCenter.clone().add(SPAWN_CENTER_OFFSET, 1, SPAWN_CENTER_OFFSET); final Location playerSpawn = platformCenter.clone().add(SPAWN_CENTER_OFFSET, 1, SPAWN_CENTER_OFFSET);
playerSpawns.put(pp, playerSpawn); playerSpawns.put(pp, playerSpawn);
playerGenerators.put(pp, gen); playerGenerators.put(pp, gen);
pp.player.teleport(playerSpawn); Compat.teleport(pp.player, playerSpawn);
} }
} }

View file

@ -5,6 +5,7 @@ import dev.loki.loparkour.ghost.model.GhostData;
import dev.loki.loparkour.scheduler.Scheduler; import dev.loki.loparkour.scheduler.Scheduler;
import dev.loki.loparkour.scheduler.ScheduledTask; import dev.loki.loparkour.scheduler.ScheduledTask;
import dev.loki.loparkour.util.misc.Compat;
import dev.loki.loparkour.LoParkour; import dev.loki.loparkour.LoParkour;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -51,7 +52,7 @@ public class GhostPlayer {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
currentFrame = 0; currentFrame = 0;
task = Scheduler.get(LoParkour.getPlugin()).runTimer(this::update, 0, 1); task = Scheduler.get(LoParkour.getPlugin()).runTimerAtLocation(this::update, startLocation, 0, 1);
} }
private void update() { private void update() {
@ -67,7 +68,7 @@ public class GhostPlayer {
if (frame.getTimestamp() > elapsed) { if (frame.getTimestamp() > elapsed) {
break; break;
} }
entity.teleport(frame.toLocation(world)); Compat.teleport(entity, frame.toLocation(world));
currentFrame++; currentFrame++;
} }

View file

@ -7,6 +7,7 @@ import dev.loki.loparkour.ghost.replay.PlayerGhost;
import dev.loki.loparkour.player.core.ParkourUser; import dev.loki.loparkour.player.core.ParkourUser;
import dev.loki.loparkour.scheduler.ScheduledTask; import dev.loki.loparkour.scheduler.ScheduledTask;
import dev.loki.loparkour.scheduler.Scheduler; import dev.loki.loparkour.scheduler.Scheduler;
import dev.loki.loparkour.util.misc.Compat;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -63,14 +64,15 @@ public class GhostReplay {
ParkourUser.leave(viewer); ParkourUser.leave(viewer);
} }
final Location start = run.getFrames().get(FIRST_FRAME).toLocation(world); final Location start = run.getFrames().get(FIRST_FRAME).toLocation(world);
viewer.teleport(start); Compat.teleport(viewer, start);
moved = true; moved = true;
ghost = new PlayerGhost(viewer, run.getPlayerName()); ghost = new PlayerGhost(viewer, run.getPlayerName());
if (ghost.spawn(start)) { if (ghost.spawn(start)) {
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
frameIndex = FIRST_FRAME; frameIndex = FIRST_FRAME;
current = start; current = start;
task = Scheduler.get(LoParkour.getPlugin()).runTimer(this::tick, TICK_DELAY, TICK_PERIOD); task = Scheduler.get(LoParkour.getPlugin()).runTimerAtLocation(this::tick, start,
TICK_DELAY, TICK_PERIOD);
} else { } else {
finish(); finish();
} }
@ -106,7 +108,7 @@ public class GhostReplay {
ghost = null; ghost = null;
} }
if (moved && viewer.isOnline()) { if (moved && viewer.isOnline()) {
viewer.teleport(returnTo); Compat.teleport(viewer, returnTo);
} }
onFinish.run(); onFinish.run();
} }

View file

@ -10,6 +10,7 @@ import dev.loki.loparkour.hook.floodgate.FloodgateHook;
import dev.loki.loparkour.menu.core.screen.ParkourOption; import dev.loki.loparkour.menu.core.screen.ParkourOption;
import dev.loki.loparkour.player.data.PreviousData; import dev.loki.loparkour.player.data.PreviousData;
import dev.loki.loparkour.session.core.Session; import dev.loki.loparkour.session.core.Session;
import dev.loki.loparkour.util.misc.Compat;
import dev.loki.loparkour.util.text.ColorUtil; import dev.loki.loparkour.util.text.ColorUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -131,7 +132,7 @@ public abstract class ParkourUser {
} }
public void teleport(@NotNull Location to) { public void teleport(@NotNull Location to) {
player.teleport(to); Compat.teleport(player, to);
} }
public void send(String message) { public void send(String message) {

View file

@ -4,6 +4,7 @@ import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.config.core.Config; import dev.loki.loparkour.config.core.Config;
import dev.loki.loparkour.config.options.OptionGeneral; import dev.loki.loparkour.config.options.OptionGeneral;
import dev.loki.loparkour.reward.core.Reward; import dev.loki.loparkour.reward.core.Reward;
import dev.loki.loparkour.util.misc.Compat;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@ -61,7 +62,7 @@ public class PreviousData {
if (!urgent) { if (!urgent) {
PaperLib.teleportAsync(player, to).thenRun(() -> apply(player)); PaperLib.teleportAsync(player, to).thenRun(() -> apply(player));
} else { } else {
player.teleport(to); Compat.teleport(player, to);
apply(player); apply(player);
} }

View file

@ -38,4 +38,20 @@ final class BukkitBackend implements Scheduler.Backend {
public ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks) { public ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks) {
return Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, task, delayTicks, periodTicks)::cancel; return Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, task, delayTicks, periodTicks)::cancel;
} }
@Override
public ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks) {
return Bukkit.getScheduler().runTaskLater(plugin, task, delayTicks)::cancel;
}
@Override
public ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location,
long delayTicks, long periodTicks) {
return Bukkit.getScheduler().runTaskTimer(plugin, task, delayTicks, periodTicks)::cancel;
}
@Override
public ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity) {
return Bukkit.getScheduler().runTask(plugin, task)::cancel;
}
} }

View file

@ -20,21 +20,27 @@ final class FoliaBackend implements Scheduler.Backend {
private static final String GLOBAL_SCHEDULER_CLASS = "GlobalRegionScheduler"; private static final String GLOBAL_SCHEDULER_CLASS = "GlobalRegionScheduler";
private static final String ASYNC_SCHEDULER_CLASS = "AsyncScheduler"; private static final String ASYNC_SCHEDULER_CLASS = "AsyncScheduler";
private static final String REGION_SCHEDULER_CLASS = "RegionScheduler";
private final Plugin plugin; private final Plugin plugin;
private final Object globalScheduler; private final Object globalScheduler;
private final Object asyncScheduler; private final Object asyncScheduler;
private final Object regionScheduler;
private final Method globalRun; private final Method globalRun;
private final Method globalRunDelayed; private final Method globalRunDelayed;
private final Method globalRunAtFixedRate; private final Method globalRunAtFixedRate;
private final Method asyncRunNow; private final Method asyncRunNow;
private final Method asyncRunAtFixedRate; private final Method asyncRunAtFixedRate;
private final Method regionRunDelayed;
private final Method regionRunAtFixedRate;
private final Method entityExecute;
private final Method taskCancel; private final Method taskCancel;
FoliaBackend(Plugin plugin) throws ReflectiveOperationException { FoliaBackend(Plugin plugin) throws ReflectiveOperationException {
this.plugin = plugin; this.plugin = plugin;
this.globalScheduler = scheduler("getGlobalRegionScheduler"); this.globalScheduler = scheduler("getGlobalRegionScheduler");
this.asyncScheduler = scheduler("getAsyncScheduler"); this.asyncScheduler = scheduler("getAsyncScheduler");
this.regionScheduler = scheduler("getRegionScheduler");
this.globalRun = method(GLOBAL_SCHEDULER_CLASS, "run", Plugin.class, Consumer.class); this.globalRun = method(GLOBAL_SCHEDULER_CLASS, "run", Plugin.class, Consumer.class);
this.globalRunDelayed = method(GLOBAL_SCHEDULER_CLASS, "runDelayed", this.globalRunDelayed = method(GLOBAL_SCHEDULER_CLASS, "runDelayed",
Plugin.class, Consumer.class, long.class); 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.asyncRunNow = method(ASYNC_SCHEDULER_CLASS, "runNow", Plugin.class, Consumer.class);
this.asyncRunAtFixedRate = method(ASYNC_SCHEDULER_CLASS, "runAtFixedRate", this.asyncRunAtFixedRate = method(ASYNC_SCHEDULER_CLASS, "runAtFixedRate",
Plugin.class, Consumer.class, long.class, long.class); 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"); this.taskCancel = Class.forName(SCHEDULER_PACKAGE + "ScheduledTask").getMethod("cancel");
} }
@ -67,6 +79,29 @@ final class FoliaBackend implements Scheduler.Backend {
consumer(task), delayTicks, periodTicks)); 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 @Override
public ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks) { public ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks) {
return wrap(invoke(asyncRunAtFixedRate, asyncScheduler, plugin, return wrap(invoke(asyncRunAtFixedRate, asyncScheduler, plugin,

View file

@ -99,6 +99,49 @@ public final class Scheduler {
return backend.runTimerAsync(task, delayTicks, periodTicks); return backend.runTimerAsync(task, delayTicks, periodTicks);
} }
/**
* Runs the task once on the region thread owning the location.
*
* <p>On Bukkit this is a plain delayed task; on Folia it uses the region
* scheduler, so block access around the location is legal.
*
* @param task the task to run
* @param location the location whose region owns the task
* @param delayTicks delay in ticks
* @return a handle used to cancel the task
*/
public ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks) {
return backend.runAtLocation(task, location, delayTicks);
}
/**
* Runs the task repeatedly on the region thread owning the location.
*
* @param task the task to run
* @param location the location whose region owns the task
* @param delayTicks first run delay in ticks
* @param periodTicks period between runs in ticks
* @return a handle used to cancel the task
*/
public ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location,
long delayTicks, long periodTicks) {
return backend.runTimerAtLocation(task, location, delayTicks, periodTicks);
}
/**
* Runs the task on the entity's thread on the next tick.
*
* <p>On Bukkit this is a plain sync task; on Folia it uses the entity
* scheduler, so entity access (teleport, inventory) is legal.
*
* @param task the task to run
* @param entity the entity whose thread owns the task
* @return a handle used to cancel the task
*/
public ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity) {
return backend.runAtEntity(task, entity);
}
private static Backend createBackend(Plugin plugin) { private static Backend createBackend(Plugin plugin) {
if (FOLIA) { if (FOLIA) {
try { try {
@ -132,5 +175,12 @@ public final class Scheduler {
ScheduledTask runTimer(Runnable task, long delayTicks, long periodTicks); ScheduledTask runTimer(Runnable task, long delayTicks, long periodTicks);
ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks); ScheduledTask runTimerAsync(Runnable task, long delayTicks, long periodTicks);
ScheduledTask runAtLocation(Runnable task, org.bukkit.Location location, long delayTicks);
ScheduledTask runTimerAtLocation(Runnable task, org.bukkit.Location location,
long delayTicks, long periodTicks);
ScheduledTask runAtEntity(Runnable task, org.bukkit.entity.Entity entity);
} }
} }

View file

@ -74,7 +74,7 @@ public class SessionStateManager {
return; return;
} }
tickTask = Scheduler.get(LoParkour.getPlugin()).runTimer(() -> { tickTask = Scheduler.get(LoParkour.getPlugin()).runTimerAtLocation(() -> {
if (session.generator() != null) { if (session.generator() != null) {
try { try {
session.generator().tick(); session.generator().tick();
@ -86,7 +86,7 @@ public class SessionStateManager {
p.player.sendMessage("§c[LoParkour] Tick error: " + t.getMessage())); p.player.sendMessage("§c[LoParkour] Tick error: " + t.getMessage()));
} }
} }
}, 0, 1); // Run every tick (1 = 50ms) }, spawnLocation, 0, 1); // Run every tick (1 = 50ms)
} }
/** /**

View file

@ -1,11 +1,16 @@
package dev.loki.loparkour.util.misc; package dev.loki.loparkour.util.misc;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.scheduler.Scheduler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.structure.StructureManager; import org.bukkit.structure.StructureManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -106,6 +111,18 @@ public final class Compat {
return null; return null;
} }
/**
* Teleports an entity. Direct on Bukkit; on Folia the call is routed to the
* entity scheduler because entity access from other threads is illegal.
*/
public static void teleport(@NotNull Entity entity, @NotNull Location location) {
if (Scheduler.isFolia()) {
Scheduler.get(LoParkour.getPlugin()).runAtEntity(() -> entity.teleport(location), entity);
} else {
entity.teleport(location);
}
}
/** /**
* Resolves a {@link PotionEffectType} by name (JUMP → JUMP_BOOST, SLOW → * Resolves a {@link PotionEffectType} by name (JUMP → JUMP_BOOST, SLOW →
* SLOWNESS were renamed in 1.21), or {@code null} when none exists. * SLOWNESS were renamed in 1.21), or {@code null} when none exists.

View file

@ -0,0 +1,12 @@
name: 'LoParkour'
description: 'BETA - Advanced infinitely generating parkour plugin.'
author: loki
version: ${version}
api-version: ${apiVersion}
main: dev.loki.loparkour.LoParkour
softdepend: [floodgate, Vault, PlaceholderAPI, Multiverse-Core]
commands:
loparkour:
aliases: [parkour, lpk]
usage: /<command> [arguments]
description: Main command for LoParkour

View file

@ -46,6 +46,14 @@ class ArchitectureTest {
.should().callMethod(org.bukkit.Bukkit.class, "getScheduler") .should().callMethod(org.bukkit.Bukkit.class, "getScheduler")
.because("Bukkit.getScheduler() does not exist on Folia")); .because("Bukkit.getScheduler() does not exist on Folia"));
@ArchTest
static final ArchRule NO_DIRECT_TELEPORT_OUTSIDE_COMPAT = freeze(
noClasses().that().resideOutsideOfPackage(ROOT + ".util.misc..")
.should().callMethod(org.bukkit.entity.Entity.class, "teleport",
org.bukkit.Location.class)
.because("teleports must go through Compat.teleport so they run "
+ "on the entity thread on Folia"));
@ArchTest @ArchTest
static final ArchRule NO_LEGACY_LOLIB = static final ArchRule NO_LEGACY_LOLIB =
noClasses().should().dependOnClassesThat().resideInAPackage("dev.lolib.."); noClasses().should().dependOnClassesThat().resideInAPackage("dev.lolib..");

View file

@ -1,6 +1,7 @@
# #
#Tue Oct 06 13:42:44 CEST 2026 #Sat Oct 10 15:00:30 CEST 2026
no\ classes\ that\ reside\ in\ a\ package\ 'dev.loki.loparkour.api..'\ should\ depend\ on\ classes\ that\ reside\ in\ any\ package\ ['dev.loki.loparkour.menu..',\ 'dev.loki.loparkour.command..',\ 'dev.loki.loparkour.storage..',\ 'dev.loki.loparkour.listener..',\ 'dev.loki.loparkour.hook..']=d1d8a9d7-476c-4f86-adda-8531054aea1f no\ classes\ that\ reside\ in\ a\ package\ 'dev.loki.loparkour.api..'\ should\ depend\ on\ classes\ that\ reside\ in\ any\ package\ ['dev.loki.loparkour.menu..',\ 'dev.loki.loparkour.command..',\ 'dev.loki.loparkour.storage..',\ 'dev.loki.loparkour.listener..',\ 'dev.loki.loparkour.hook..']=d1d8a9d7-476c-4f86-adda-8531054aea1f
no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.scheduler..'\ should\ call\ method\ Bukkit.getScheduler(),\ because\ Bukkit.getScheduler()\ does\ not\ exist\ on\ Folia=f1e3c34b-9b02-40e6-83a6-0269e173eb83 no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.scheduler..'\ should\ call\ method\ Bukkit.getScheduler(),\ because\ Bukkit.getScheduler()\ does\ not\ exist\ on\ Folia=f1e3c34b-9b02-40e6-83a6-0269e173eb83
no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.scheduler..'\ should\ depend\ on\ classes\ that\ are\ assignable\ to\ org.bukkit.scheduler.BukkitRunnable,\ because\ all\ tasks\ go\ through\ scheduler/\ so\ they\ work\ on\ Folia=339ab3ea-28aa-4f4b-a1e4-6c69e3ff0a0a no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.scheduler..'\ should\ depend\ on\ classes\ that\ are\ assignable\ to\ org.bukkit.scheduler.BukkitRunnable,\ because\ all\ tasks\ go\ through\ scheduler/\ so\ they\ work\ on\ Folia=339ab3ea-28aa-4f4b-a1e4-6c69e3ff0a0a
no\ classes\ that\ reside\ outside\ of\ package\ 'dev.loki.loparkour.util.misc..'\ should\ call\ method\ Entity.teleport(Location),\ because\ teleports\ must\ go\ through\ Compat.teleport\ so\ they\ run\ on\ the\ entity\ thread\ on\ Folia=cea999b4-4780-4ff1-ae71-5394d5efa19e
slices\ matching\ 'dev.loki.loparkour.(*)..'\ should\ be\ free\ of\ cycles=58784f63-3f60-4edb-9733-fa0d7e11b877 slices\ matching\ 'dev.loki.loparkour.(*)..'\ should\ be\ free\ of\ cycles=58784f63-3f60-4edb-9733-fa0d7e11b877