blob: 2fa2017d02ef0ec6db3f920bf7314096ed632aa1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package cc.polyfrost.oneconfig.utils;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.Stage;
import cc.polyfrost.oneconfig.events.event.TickEvent;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
public class TickDelay {
private int delay;
private final Runnable function;
public TickDelay(Runnable functionName, int ticks) {
EventManager.INSTANCE.getEventBus().register(this);
delay = ticks;
function = functionName;
}
@Subscribe
public void onTick(TickEvent event) {
if (event.stage == Stage.START) {
// Delay expired
if (delay < 1) {
function.run();
EventManager.INSTANCE.getEventBus().unregister(this);
}
delay--;
}
}
}
|