Closed bananasmoothii closed 1 year ago
As far as I have understand the minestom approach, you always "build a server yourself" by initializing a MinecraftServer
instance. This can be seen on this wiki page https://wiki.minestom.net/setup/your-first-server.
Here you call MinecraftServer minecraftServer = MinecraftServer.init();
. This means you do actually have a minecraft server instance.
MCCoroutine simply needs a lifecycle instance (the coroutine session is created and disposed along with it) where MinecraftServer
makes the most sense in this context.
You are free to move the MinecraftServer
instance to a static (or companion) field because it does not make any difference in this case.
Yeah... There is a flaw in Minestom's design so there is no real way around it. You have to make a MinecraftServer
instance indeed, but you use it just to call .init()
and .start()
A coroutine needs to live in a scope. For Kotlin, these are called Coroutine Scopes. See https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/
For Minestom, I have implemented 2 scope types. ExtensionScope
and MinecraftServerScope
. Kotlin Coroutines offers the GlobalScope per default, which allows to do something like GlobalScope.launch
. To indicate that the coroutine lives in the scope of the entire MinecraftServer (start/stop) it makes sense to bind the scope to it. Therefore, I have added the launch
function to the MinecraftServer
instance.
I think technically, it makes sense to indicate scopes on API level.
~
You are free to add your own launch extension function or move the MinecraftServer instance to a companion object of your main class. I do not care.
Hi, you recently implemented MCCoroutines for Minestom and I'd like to firstly thank you for that.
But there is a little issue on the implementation of
server.launch { }
: in Minestom, we usually don't store anyMinecraftServer
instance because every method in that class is static. That means that instead ofserver.launch { }
, we should be able to doMinecraftServer.launch { }
.Unfortunately,
MinecraftServer
is a java class and doesn't have any companion object, so making an extension function for the companion object is impossible. A workaround would be to changefun MinecraftServer.launch
to justfun minecraftServerLaunch
.For now, I am using this: