Add @LinkedTimer

A method of a linked class annotated with @LinkedTimer(delay, period) is run
repeatedly by the linker, on Spigot and Velocity. The method must not have
parameters, its return value is ignored. It is called through a MethodHandle
bound once when linking instead of reflection; LambdaMetafactory cannot be used
as the linker and the linked classes are in different class loaders.

The unit defaults to ticks and can be set to milliseconds up to hours; the
Unit enum converts it to ticks for Spigot and to a TimeUnit for Velocity.
HullHiderCommand uses it for its tick task.
This commit is contained in:
2026-10-31 16:11:28 +01:00
parent b78fab3172
commit 9598b1c961
5 changed files with 146 additions and 2 deletions
@@ -32,6 +32,7 @@ import de.steamwar.command.*;
import de.steamwar.linkage.AbstractLinker;
import de.steamwar.linkage.EventMode;
import de.steamwar.linkage.LinkedInstance;
import de.steamwar.linkage.LinkedTimer;
import de.steamwar.messages.Chatter;
import de.steamwar.network.packets.PacketHandler;
import de.steamwar.persistent.ReloadablePlugin;
@@ -164,6 +165,11 @@ public class VelocityCore implements ReloadablePlugin {
}
}
@Override
protected void scheduleTimer(Runnable runnable, long delay, long period, LinkedTimer.Unit unit) {
schedule(runnable).delay(unit.toTimeUnit(delay), unit.getTimeUnit()).repeat(unit.toTimeUnit(period), unit.getTimeUnit()).schedule();
}
@Override
protected void unlinkObject(Object any) {
if (any instanceof PacketHandler) {