packagedemo;importnet.minestom.server.MinecraftServer;importnet.minestom.server.entity.Player;importnet.minestom.server.event.GlobalEventHandler;importnet.minestom.server.event.player.PlayerLoginEvent;importnet.minestom.server.instance.*;importnet.minestom.server.instance.batch.ChunkBatch;importnet.minestom.server.instance.block.Block;importnet.minestom.server.coordinate.Pos;importnet.minestom.server.world.biomes.Biome;importjava.util.Arrays;importjava.util.List;publicclassMainDemo {publicstaticvoidmain(String[] args) {// InitializationMinecraftServer minecraftServer =MinecraftServer.init();InstanceManager instanceManager =MinecraftServer.getInstanceManager();// Create the instanceInstanceContainer instanceContainer =instanceManager.createInstanceContainer();// Set the ChunkGeneratorinstanceContainer.setGenerator(unit ->unit.modifier().fillHeight(0,40,Block.GRASS_BLOCK));// Add an event callback to specify the spawning instance (and the spawn position)GlobalEventHandler globalEventHandler =MinecraftServer.getGlobalEventHandler();globalEventHandler.addListener(PlayerLoginEvent.class, event -> {finalPlayer player =event.getPlayer();event.setSpawningInstance(instanceContainer);player.setRespawnPoint(newPos(0,42,0)); });// Start the server on port 25565minecraftServer.start("0.0.0.0",25565); }}
Building the server JAR
Once you have created your Minestom server, you will probably want to build it and distribute it to a host or friend. To do so we will set up the Shadow plugin so that we can make a final working uber (fat) jar.
Side note: For Maven users, you will need the "Shade" plugin. If you use Maven and would like to contribute an example it would be appreciated :)
You can find the full documentation for the Shadow plugin here.
First, let's add the Shadow plugin to our project.
plugins { id "com.github.johnrengelman.shadow" version "8.1.1"}
plugins {id("com.github.johnrengelman.shadow") version "8.1.1"}
If the JAR is meant to be run, which it probably is, you also need to specify the class containing the main method like so,
jar { manifest {// Change this to your main class attributes 'Main-Class': 'org.example.Main' }}
tasks.withType<Jar> {manifest {// Change this to your main class attributes["Main-Class"] ="org.example.Main" }}
With all of this done, all we need to do is run the shadowJar task to create a working uber (fat) jar! (The jar will be put in /build/libs/ by default)
Now, just to be sure that you understood everything, here is a complete build.gradle/build.gradle.kts file.
plugins { id 'java' id "com.github.johnrengelman.shadow" version "8.1.1"}group 'org.example'version '1.0-SNAPSHOT'repositories { mavenCentral() maven { url 'https://jitpack.io' }}dependencies {// Change this to the latest version implementation 'com.github.Minestom:Minestom:VERSION'}jar { manifest {// Change this to your main class attributes 'Main-Class': 'org.example.Main' }}
plugins {id("java")id("com.github.johnrengelman.shadow") version "8.1.1"}group ="org.example"version ="1.0-SNAPSHOT"repositories {mavenCentral()maven(url ="https://jitpack.io")}dependencies {// Change this to the latest versionimplementation("com.github.Minestom.Minestom:Minestom:VERSION")}tasks.withType<Jar> {manifest {// Change this to your main class attributes["Main-Class"] ="org.example.Main" }}