Getting started
Publication coordinates are not stable yet. The dependency examples assume your server is a project in this repository and use its type-safe project accessors.
Also, make sure you understand Minestom before continuing as this guide won’t cover it.
Add the foundation
Section titled “Add the foundation”Not all Twaddle features need a running core. Look at the page of your feature to see what it needs.
dependencies { implementation(projects.twaddleCore)}The application lifecycle has four phases:
- Twaddle creates the root context.
- Pre-init modules are installed.
- Minestom is initialized.
- Modules that need the server are installed.
Create the server directly and wrap the process lifetime with runTwaddleApplication.
When the application block finishes or fails, the context cancels lifetime coroutine work and closes owned resources.
import kotlinx.coroutines.awaitCancellationimport net.minestom.server.Authimport net.minestom.server.MinecraftServerimport org.everbuild.twaddle.core.runTwaddleApplication
suspend fun main() = runTwaddleApplication { cx -> // Install pre-init modules here
val server = MinecraftServer.init(Auth.Online()) val serverCx = cx.initialized(server)
// Pass serverCx to post-init modules here
server.start("0.0.0.0", 25565) awaitCancellation()}Create a TwaddleContext manually and wrap the process lifetime with try/finally.
import net.minestom.server.Auth;import net.minestom.server.MinecraftServer;import org.everbuild.twaddle.core.TwaddleContext;import java.util.concurrent.CountDownLatch;
void main() throws InterruptedException { var cx = TwaddleContext.root();
try { // Install pre-init modules here
var minecraftServer = MinecraftServer.init(new Auth.Online()); var serverCx = cx.initialized(minecraftServer);
// Pass serverCx to post-init modules here
minecraftServer.start("0.0.0.0", 25565); new CountDownLatch(1).await(); } finally { cx.shutdownNow(); }}The wait after start(...) is deliberate. Minestom starts its server threads and returns, while the Twaddle context must
stay alive for as long as those threads do. Replace the indefinite wait with your application’s shutdown signal when it
has one.
Adopt optional capabilities
Section titled “Adopt optional capabilities”Continue with Inventory transfer rules for the first optional capability.