Skip to main content
The MinecraftServer class manages server-side game logic, including level management, player connections, tick processing, and world saving.

Constructor

Creates a new MinecraftServer instance with default settings.

Initialization

run

Starts the server with the specified world seed.
__int64
World generation seed
void*
Platform-specific parameters

main

Static entry point for starting the server.

Server Control

halt

Stops the server gracefully, saving all data.

HaltServer

Static method to halt the server.
bool
default:"false"
Whether to skip saving due to primary player sign-out

Suspend

Suspends the server (for console suspend/resume).

IsSuspending

Returns whether the server is currently suspending.

IsServerPaused

Returns whether the server is paused.

Tick System

tick

Processes one server tick (called 20 times per second). Handles:
  • Level updates
  • Entity updates
  • Player updates
  • Chunk loading/unloading
  • Scheduled events

Level Management

getLevel

Returns the server level for a specific dimension.
int
Dimension ID:
  • 0 - Overworld
  • -1 - Nether (Hell)
  • 1 - The End

setLevel

Sets the server level for a specific dimension.
int
Dimension ID
ServerLevel*
The server level instance

Player Management

getPlayers

Returns the player list manager.

setPlayers

Sets the player list manager.

getPlayerList

Static method to get the player list from the server instance.

Connection Management

getConnection

Returns the server connection handler.

Saving

saveAllChunks

Saves all loaded chunks across all dimensions.

saveGameRules

Saves the current game rules to disk.

setSaveOnExit

Sets whether to save when the server exits.
bool
Whether to save on exit

broadcastStartSavingPacket

Notifies all clients that saving has started.

broadcastStopSavingPacket

Notifies all clients that saving has completed.

Game Settings

setMaxBuildHeight

Sets the maximum build height for the world.
int
Maximum Y coordinate for building

getMaxBuildHeight

Returns the maximum build height.

isAnimals

Returns whether animal spawning is enabled.

setAnimals

Enables or disables animal spawning.

isNpcsEnabled

Returns whether NPC (villager) spawning is enabled.

setNpcsEnabled

Enables or disables NPC spawning.

isPvpAllowed

Returns whether PvP is enabled.

setPvpAllowed

Enables or disables player vs player combat.

isFlightAllowed

Returns whether flight is allowed in survival mode.

setFlightAllowed

Enables or disables flight in survival mode.

isNetherEnabled

Returns whether the Nether dimension is enabled.

isHardcore

Returns whether the server is in hardcore mode.

Console Commands

handleConsoleInput

Processes a console command.
const wstring&
The command message
ConsoleInputSource*
The source of the command

handleConsoleInputs

Processes all queued console commands.

getCommandDispatcher

Returns the command dispatcher.

getConsoleName

Returns the console name for command output.

Time Management

SetTimeOfDay

Sets the time of day (0-24000).
__int64
Time in ticks (0 = dawn, 6000 = noon, 12000 = dusk, 18000 = midnight)

SetTime

Sets the total world time.
__int64
Total world time in ticks

Network Packet Queue Management

canSendOnSlowQueue

Checks if a player can send packets on the slow queue.
INetworkPlayer*
The network player to check

cycleSlowQueueIndex

Cycles to the next player in the slow queue rotation.

Progress Updates

setProgress

Updates the progress status during level loading.
const wstring&
Status message
int
Progress percentage (0-100)

endProgress

Ends the progress display.

Static Helpers

getInstance

Returns the singleton server instance.

serverHalted

Returns whether the server has been halted.

saveOnExitAnswered

Returns whether the save-on-exit question has been answered.

resetFlags

Resets server state flags.

Public Member Variables

ServerConnection*
Server network connection handler
Settings*
Server settings
ServerLevelArray
Array of server levels (one per dimension)
bool
Whether the server is running
bool
Whether the server has stopped
int
Current tick counter
wstring
Current progress status message
int
Current progress value
bool
Whether online mode is enabled
bool
Whether animal spawning is enabled
bool
Whether NPC spawning is enabled
bool
Whether PvP is enabled
bool
Whether flight is allowed
wstring
Message of the day
int
Maximum build height
DWORD
UGC (User Generated Content) players version counter
DWORD
Currently loaded texture pack ID

Static Constants

Server version string.
Tick statistics collection span (100 ticks).
Milliseconds per tick (50ms for 20 TPS).

Example Usage

Starting a Server

Managing Game Settings

Working with Levels

Time Management

Saving

Graceful Shutdown

Thread Safety

The server uses a separate thread for post-processing chunks during level creation. Always use the provided synchronization primitives when accessing shared data.

Performance Considerations

The server runs at 20 ticks per second (TPS). Each tick must complete within 50ms to maintain performance. The slow queue system prevents packet flooding by rotating which player can send packets each tick.