Added configurable Vein Miner animation
This commit is contained in:
45
src/main/java/wtf/hak/survivalfabric/utils/Scheduler.java
Normal file
45
src/main/java/wtf/hak/survivalfabric/utils/Scheduler.java
Normal file
@ -0,0 +1,45 @@
|
||||
package wtf.hak.survivalfabric.utils;
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Scheduler {
|
||||
|
||||
private static Scheduler INSTANCE;
|
||||
|
||||
private final Map<Runnable, Long> tasks = new ConcurrentHashMap<>();
|
||||
|
||||
public Scheduler() {
|
||||
ServerTickEvents.END_SERVER_TICK.register((server) -> {
|
||||
for(Runnable task : tasks.keySet()) {
|
||||
long delay = tasks.get(task);
|
||||
if(delay <= 0) {
|
||||
task.run();
|
||||
tasks.remove(task);
|
||||
} else {
|
||||
tasks.put(task, delay-1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void scheduleTask(Runnable task) {
|
||||
scheduleTask(task, 0L);
|
||||
}
|
||||
|
||||
public void scheduleTask(Runnable task, long delay) {
|
||||
tasks.put(task, delay);
|
||||
}
|
||||
|
||||
public static Scheduler get() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static Scheduler initialize() {
|
||||
INSTANCE = new Scheduler();
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user