I want to start a springboot webserver from a Minecraft plugin written in java, ive tried adding springboot module to the project in IntelliJ, but the server doesn't start when the plugin is loaded
I want to start a springboot webserver from a Minecraft plugin written in java, ive tried adding springboot module to the project in IntelliJ, but the server doesn't start when the plugin is loaded
Yes, it's possible. But you SHOULD do it async.
Actually, you have the minecraft server start that a Thread. This one will open the port, and run all plugin.
If you try to run Spring on this thread, it will start an instance of the server, and wait for connection ... on the same thread of the minecraft server.
So, the server will wait your code to stop running before doing something else, and it will not be able to receive packet.
How to fix it ?
You should run your code async, like that :
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
// here you can start your server
});
You can also just a basic java thread :
new Thread(() -> {
// here start your server
}).start();