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
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.
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,
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.
Last updated
Was this helpful?
