Skip to main content

MinecraftServer Class

The main server class used to initialize, start, and manage the Minestom server. All managers and core functionality are accessed through this class.

Initialization

init
static MinecraftServer
Initializes the server with offline authentication mode.Returns: The MinecraftServer instance
MinecraftServer server = MinecraftServer.init();
init(Auth)
static MinecraftServer
Initializes the server with specified authentication.Parameters:
  • auth - Authentication mode (online/offline)
Returns: The MinecraftServer instance
MinecraftServer server = MinecraftServer.init(new Auth.Online());

Server Lifecycle

start(String, int)
void
Starts the server on the specified address and port.Parameters:
  • address - Server IP address
  • port - Server port number
Throws: IllegalStateException if called before init() or if server is already running
server.start("0.0.0.0", 25565);
start(SocketAddress)
void
Starts the server on the specified socket address.Parameters:
  • address - Server socket address
server.start(new InetSocketAddress("localhost", 25565));
stopCleanly()
static void
Stops the server properly (saves data, kicks players, etc.).
MinecraftServer.stopCleanly();

Manager Getters

All manager getters are static methods that provide access to core server functionality.
getInstanceManager()
static InstanceManager
Gets the instance manager for managing worlds.Returns: The InstanceManager instance
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
InstanceContainer world = instanceManager.createInstanceContainer();
getConnectionManager()
static ConnectionManager
Gets the connection manager for handling player connections.Returns: The ConnectionManager instance
ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
Collection<Player> players = connectionManager.getOnlinePlayers();
getBlockManager()
static BlockManager
Gets the block manager for registering block handlers and placement rules.Returns: The BlockManager instance
BlockManager blockManager = MinecraftServer.getBlockManager();
blockManager.registerHandler("custom:block", () -> new MyBlockHandler());
getCommandManager()
static CommandManager
Gets the command manager for registering commands.Returns: The CommandManager instance
getSchedulerManager()
static SchedulerManager
Gets the scheduler manager for task scheduling.Returns: The SchedulerManager instance
getGlobalEventHandler()
static GlobalEventHandler
Gets the global event handler for registering event listeners.Returns: The GlobalEventHandler instance
GlobalEventHandler eventHandler = MinecraftServer.getGlobalEventHandler();
eventHandler.addListener(PlayerLoginEvent.class, event -> {
    event.setSpawningInstance(instanceManager.getInstances().iterator().next());
});
getRecipeManager()
static RecipeManager
Gets the recipe manager for handling recipes.Returns: The RecipeManager instance
getTeamManager()
static TeamManager
Gets the team manager for managing scoreboard teams.Returns: The TeamManager instance
getBenchmarkManager()
static BenchmarkManager
Gets the benchmark manager for server monitoring.Returns: The BenchmarkManager instance
getExceptionManager()
static ExceptionManager
Gets the exception manager for handling server exceptions.Returns: The ExceptionManager instance
getBossBarManager()
static BossBarManager
Gets the boss bar manager for managing boss bars.Returns: The BossBarManager instance

Server Properties

getBrandName()
static String
Gets the current server brand name displayed to clients.Returns: The server brand name (default: “Minestom”)
setBrandName(String)
static void
Changes the server brand name and broadcasts it to all players.Parameters:
  • brandName - The new server brand name
MinecraftServer.setBrandName("My Custom Server");
getDifficulty()
static Difficulty
Gets the server difficulty level.Returns: The current Difficulty
setDifficulty(Difficulty)
static void
Changes the server difficulty and notifies all clients.Parameters:
  • difficulty - The new difficulty level
MinecraftServer.setDifficulty(Difficulty.HARD);
getCompressionThreshold()
static int
Gets the compression threshold. A value of 0 means compression is disabled.Returns: The compression threshold in bytes
setCompressionThreshold(int)
static void
Changes the compression threshold. Must be called before server start.Parameters:
  • compressionThreshold - Threshold in bytes, 0 to disable
Throws: IllegalStateException if called after server start
MinecraftServer.setCompressionThreshold(256);

Server State

isStarted()
static boolean
Checks if the server is currently running.Returns: true if the server is started, false otherwise
isStopping()
static boolean
Checks if the server is stopping or stopped.Returns: true if the server is not running, false otherwise
process()
static ServerProcess
Gets the current server process.Returns: The ServerProcess instance

ServerProcess Interface

The ServerProcess interface provides access to all server subsystems and is the underlying implementation of MinecraftServer.

Core Managers

connection()
ConnectionManager
Handles incoming connections and player management.
instance()
InstanceManager
Handles registered instances (worlds).
block()
BlockManager
Handles block handlers and placement rules.
command()
CommandManager
Handles registered commands.
recipe()
RecipeManager
Handles registered recipes shown to clients.
team()
TeamManager
Handles registered scoreboard teams.
eventHandler()
GlobalEventHandler
Gets the global event handler for event registration.
scheduler()
SchedulerManager
Main scheduler ticked at the server rate.
advancement()
AdvancementManager
Handles registered advancements.
exception()
ExceptionManager
Handles all thrown exceptions from the server.
dispatcher()
ThreadDispatcher<Chunk, Entity>
Dispatcher for tickable game objects.

Example: Basic Server Setup

public class ServerExample {
    public static void main(String[] args) {
        // Initialize server
        MinecraftServer server = MinecraftServer.init();
        
        // Configure server
        MinecraftServer.setBrandName("My Server");
        MinecraftServer.setDifficulty(Difficulty.NORMAL);
        
        // Create instance
        InstanceManager instanceManager = MinecraftServer.getInstanceManager();
        InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
        instanceContainer.setGenerator(unit -> unit.modifier().fillHeight(0, 40, Block.GRASS_BLOCK));
        
        // Register events
        GlobalEventHandler eventHandler = MinecraftServer.getGlobalEventHandler();
        eventHandler.addListener(PlayerLoginEvent.class, event -> {
            event.setSpawningInstance(instanceContainer);
            event.getPlayer().setRespawnPoint(new Pos(0, 42, 0));
        });
        
        eventHandler.addListener(PlayerChatEvent.class, event -> {
            event.setChatFormat(chatEvent -> 
                Component.text(chatEvent.getPlayer().getUsername() + ": ")
                    .append(chatEvent.getMessage())
            );
        });
        
        // Start server
        server.start("0.0.0.0", 25565);
    }
}
Always call MinecraftServer.init() before registering dimensions, biomes, commands, or events.
The server must be initialized with init() and configured before calling start(). Configuration changes like setCompressionThreshold() cannot be made after the server has started.

Build docs developers (and LLMs) love