mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Tick event thing
This commit is contained in:
parent
040ba417bb
commit
a3011594c0
@ -12,6 +12,7 @@ import net.minestom.server.thread.ThreadProvider;
|
||||
import net.minestom.server.utils.thread.MinestomThread;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
public final class UpdateManager {
|
||||
@ -25,6 +26,8 @@ public final class UpdateManager {
|
||||
|
||||
private ThreadProvider threadProvider;
|
||||
|
||||
private ArrayList<Runnable> tickCallbacks = new ArrayList<>();
|
||||
|
||||
{
|
||||
//threadProvider = new PerInstanceThreadProvider();
|
||||
threadProvider = new PerGroupChunkProvider();
|
||||
@ -51,6 +54,9 @@ public final class UpdateManager {
|
||||
currentTime = System.nanoTime();
|
||||
final long time = System.currentTimeMillis();
|
||||
|
||||
//Tick Callbacks
|
||||
tickCallbacks.forEach(Runnable::run);
|
||||
|
||||
// Server tick (instance/chunk/entity)
|
||||
threadProvider.update(time);
|
||||
|
||||
@ -129,6 +135,14 @@ public final class UpdateManager {
|
||||
this.threadProvider.onChunkUnload(instance, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public void addTickCallback(Runnable callback) {
|
||||
tickCallbacks.add(callback);
|
||||
}
|
||||
|
||||
public void removeTickCallback(Runnable callback) {
|
||||
tickCallbacks.remove(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the server loop
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user