Minestom wiki
Search
⌃K

Your first server

Includes everything you need to have your first server running.
Some things are needed before being able to connect to your Minestom server.
  • Initialize the server
  • Registering events/commands
  • Start the server at the specified port and address
Here is a correct example:
public static void main(String[] args) {
// Initialize the server
MinecraftServer minecraftServer = MinecraftServer.init();
// REGISTER EVENTS (set spawn instance, teleport player at spawn)
// Start the server
minecraftServer.start("0.0.0.0", 25565);
}
However even after those steps, you will not be able to connect, what we miss here is an instance (the world)
Please check the instances and events pages if you have any question about how to create/listen to one
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
globalEventHandler.addListener(PlayerLoginEvent.class, event -> {
event.setSpawningInstance(YOUR_SPAWNING_INSTANCE);
});
Here is an example of a working Minestom server
package demo;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.Player;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.event.player.PlayerLoginEvent;
import net.minestom.server.instance.*;
import net.minestom.server.instance.batch.ChunkBatch;
import net.minestom.server.instance.block.Block;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.world.biomes.Biome;
import java.util.Arrays;
import java.util.List;
public class MainDemo {
public static void main(String[] args) {
// Initialization
MinecraftServer minecraftServer = MinecraftServer.init();
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
// Create the instance
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
// Set the ChunkGenerator
instanceContainer.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 -> {
final Player player = event.getPlayer();
event.setSpawningInstance(instanceContainer);
player.setRespawnPoint(new Pos(0, 42, 0));
});
// Start the server on port 25565
minecraftServer.start("0.0.0.0", 25565);
}
}

Build the server JAR

After being able to launch the program you will probably want to build it and distribute it to a host or even a friend.
Minestom does not provide a JAR of itself for the simple reason that this is your job. You will need to build your server and include all the Minestom dependencies.
First of all, the fat JAR can be built using the Gradle shadow plugin as simple as adding
id "com.github.johnrengelman.shadow" version "7.1.0"
If the JAR is meant to be run, you also need to specify the class containing the main method.
// Code sample, be sure to modify the 'Main-Class' value
// based on your application
jar {
manifest {
attributes 'Main-Class': 'fr.themode.minestom.MinestomTest',
"Multi-Release": true
}
}
With all of this set, all that is remaining is the build command, shadow provides the handy shadowJar task that you need to run and a working JAR will magically appear!
Now, just to be sure that you understood everything, here is the complete build.gradle file that I have used to demonstrate it.
plugins {
id 'java'
id "com.github.johnrengelman.shadow" version "6.1.0"
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
// WARNING: outdated version, replace it to the latest
// Reminder: can be found at https://jitpack.io/#Minestom/Minestom
implementation 'com.github.Minestom:Minestom:1eea505da0'
}
jar {
manifest {
// WARNING: change the 'Main-Class' value
attributes 'Main-Class': 'fr.themode.minestom.MinestomTest',
"Multi-Release": true
}
}