Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

New Features #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/imgui.ini
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
/.idea/
14 changes: 4 additions & 10 deletions src/main/java/net/minestom/ui/MinestomUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import imgui.app.Application;
import net.minestom.server.MinecraftServer;
import net.minestom.server.snapshot.ServerSnapshot;
import net.minestom.server.timer.TaskSchedule;
import net.minestom.server.ServerProcess;
import org.lwjgl.glfw.GLFW;

import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -15,19 +14,14 @@ public static void launch() {
if (!initialized.compareAndSet(false, true)) {
throw new IllegalStateException("MinestomUI is already initialized");
}
var process = MinecraftServer.process();
ServerProcess process = MinecraftServer.process();
if (process == null) {
throw new IllegalStateException("Minestom server must be initialized before launching the UI");
}
ServerUI ui = new ServerUI();
new Thread(() -> Application.launch(ui)).start();

var scheduler = process.scheduler();
// Retrieve up-to-date server info every tick
scheduler.scheduleTask(() -> {
ui.snapshotReference = ServerSnapshot.update();
}, TaskSchedule.nextTick(), TaskSchedule.nextTick());

// Close the ui when the server is closed
scheduler.buildShutdownTask(() -> GLFW.glfwSetWindowShouldClose(ui.getHandle(), true));
process.scheduler().buildShutdownTask(() -> GLFW.glfwSetWindowShouldClose(ui.getHandle(), true));
}
}
Loading