Minestom wiki
Search…
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:
1
public static void main(String[] args) {
2
// Initialize the server
3
MinecraftServer minecraftServer = MinecraftServer.init();
4
5
// REGISTER EVENTS (set spawn instance, teleport player at spawn)
6
7
// Start the server
8
minecraftServer.start("0.0.0.0", 25565);
9
}
Copied!
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
1
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
2
globalEventHandler.addListener(PlayerLoginEvent.class, event -> {
3
event.setSpawningInstance(YOUR_SPAWNING_INSTANCE);
4
});
Copied!
Here is an example of a working Minestom server
1
package demo;
2
3
import net.minestom.server.MinecraftServer;
4
import net.minestom.server.entity.Player;
5
import net.minestom.server.event.GlobalEventHandler;
6
import net.minestom.server.event.player.PlayerLoginEvent;
7
import net.minestom.server.instance.*;
8
import net.minestom.server.instance.batch.ChunkBatch;
9
import net.minestom.server.instance.block.Block;
10
import net.minestom.server.coordinate.Pos;
11
import net.minestom.server.world.biomes.Biome;
12
13
import java.util.Arrays;
14
import java.util.List;
15
16
public class MainDemo {
17
18
public static void main(String[] args) {
19
// Initialization
20
MinecraftServer minecraftServer = MinecraftServer.init();
21
22
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
23
// Create the instance
24
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
25
// Set the ChunkGenerator
26
instanceContainer.setChunkGenerator(new GeneratorDemo());
27
28
// Add an event callback to specify the spawning instance (and the spawn position)
29
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler();
30
globalEventHandler.addListener(PlayerLoginEvent.class, event -> {
31
final Player player = event.getPlayer();
32
event.setSpawningInstance(instanceContainer);
33
player.setRespawnPoint(new Pos(0, 42, 0));
34
});
35
36
// Start the server on port 25565
37
minecraftServer.start("0.0.0.0", 25565);
38
}
39
40
private static class GeneratorDemo implements ChunkGenerator {
41
42
@Override
43
public void generateChunkData(@NotNull ChunkBatch batch, int chunkX, int chunkZ) {
44
// Set chunk blocks
45
for (byte x = 0; x < Chunk.CHUNK_SIZE_X; x++) {
46
for (byte z = 0; z < Chunk.CHUNK_SIZE_Z; z++) {
47
for (byte y = 0; y < 40; y++) {
48
batch.setBlock(x, y, z, Block.STONE);
49
}
50
}
51
}
52
}
53
54
@Override
55
public void fillBiomes(Biome[] biomes, int chunkX, int chunkZ) {
56
Arrays.fill(biomes, Biome.PLAINS);
57
}
58
59
@Override
60
public List<ChunkPopulator> getPopulators() {
61
return null;
62
}
63
}
64
65
}
Copied!

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
1
id "com.github.johnrengelman.shadow" version "7.1.0"
Copied!
If the JAR is meant to be run, you also need to specify the class containing the main method.
1
// Code sample, be sure to modify the 'Main-Class' value
2
// based on your application
3
jar {
4
manifest {
5
attributes 'Main-Class': 'fr.themode.minestom.MinestomTest',
6
"Multi-Release": true
7
}
8
}
Copied!
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.
1
plugins {
2
id 'java'
3
id "com.github.johnrengelman.shadow" version "6.1.0"
4
}
5
6
group 'org.example'
7
version '1.0-SNAPSHOT'
8
9
repositories {
10
mavenCentral()
11
12
maven { url 'https://repo.spongepowered.org/maven' }
13
maven { url 'https://jitpack.io' }
14
}
15
16
dependencies {
17
// WARNING: outdated version, replace it to the latest
18
// Reminder: can be found at https://jitpack.io/#Minestom/Minestom
19
implementation 'com.github.Minestom:Minestom:1eea505da0'
20
}
21
22
jar {
23
manifest {
24
// WARNING: change the 'Main-Class' value
25
attributes 'Main-Class': 'fr.themode.minestom.MinestomTest',
26
"Multi-Release": true
27
}
28
}
Copied!
Last modified 29d ago
Copy link