Skip to content

API reference / @jsprismarine/prismarine / Server / Server

Class: Server ​

Defined in: prismarine/src/Server.ts:91

JSPrismarine's main server class.

Constructors ​

Constructor ​

new Server(options): Server

Defined in: prismarine/src/Server.ts:245

Creates a new server instance.

Parameters ​

options ​

The options.

chunkAdmissionBudget? ​

number

The most chunk completions one input step admits, CHUNK_ADMISSION_BUDGET_PER_TICK by default. A replay harness changes it to show that a recorded trace, not the budget, decides what a replay admits.

config ​

Config

The config.

headless? ​

boolean = false

inboundPacketRecorder? ​

InboundPacketRecorder

Opt-in sink for accepted inbound packet bytes, which may include login identity data.

logger ​

Logger

The logger.

onStopCommandComplete? ​

() => void

Called once the shutdown a /stop started has finished and the command's feedback has settled, delivered or not.

outboundPacketRecorder? ​

OutboundPacketRecorder

Opt-in sink for encoded clientbound packets.

profile? ​

boolean = false

Record server phase and event-loop timings.

tickClock? ​

() => number

The clock the tick loop schedules and times its phases by, performance.now by default. Nothing a tick simulates reads it.

transport? ​

Transport<TransportConnection>

A transport to listen on instead of the ones the config enables, such as an in-process loopback a replay harness drives. bootstrap then binds no socket. Its connections draw their IDs from a ConnectionIds of its own.

Returns ​

Server

The server instance.

Methods ​

advanceTick() ​

advanceTick(): void

Defined in: prismarine/src/Server.ts:1145

Runs one tick now, for a harness that drives a server started with ticking disabled.

Each call is exactly one tick, run to its end before this returns, so a replay takes the same steps on any host. Activate Server.getChunkCompletionQueue first, or inputs and finished chunks are applied when they arrive. See ServerTicker.advance.

Returns ​

void

Throws ​

When the tick loop is running.


attachRemoteConsole() ​

attachRemoteConsole(remote): void

Defined in: prismarine/src/Server.ts:558

Attaches the remote console a host process talks to. Call it before bootstrap: the server enables it as it starts, reports running once it listens, reports stopping as shutdown begins, and disables it last, so the final messages leave the channel before the process exits.

Parameters ​

remote ​

RemoteConsole

Returns ​

void


bootstrap() ​

bootstrap(serverIp?, port?): Promise<void>

Defined in: prismarine/src/Server.ts:533

Starts the server.

Parameters ​

serverIp? ​

string

Optional bind address. Defaults to the configured server IP.

port? ​

number

Optional bind port. Defaults to the configured server port.

Returns ​

Promise<void>

A promise that resolves when the server is started.

Throws ​

When an enabled transport cannot listen; the message names it, its port and the cause.


broadcastPacket() ​

broadcastPacket<T>(dataPacket): Promise<void>

Defined in: prismarine/src/Server.ts:665

Sends a packet to every player on the server, in every world.

The genuinely global channel: the player list, the command tree, a shutdown notice - things that are about the server rather than about a place in it. Anything that happens somewhere belongs on World.broadcastAround, which only reaches the players near it.

Type Parameters ​

T ​

T extends NetworkPacket<unknown>

Parameters ​

dataPacket ​

T

The packet to send.

Returns ​

Promise<void>


getBanManager() ​

getBanManager(): BanManager

Defined in: prismarine/src/Server.ts:1090

Returns the ban manager.

Returns ​

BanManager

The ban manager.

Deprecated ​

Resolve it through the kernel instead: server.getKernel().get(bansToken), with bansToken from @jsprismarine/prismarine/modules/tokens.


getChatManager() ​

getChatManager(): ChatManager

Defined in: prismarine/src/Server.ts:1028

Returns the chat manager.

Returns ​

ChatManager

The chat manager.

Deprecated ​

Resolve it through the kernel instead: server.getKernel().get(chatToken), with chatToken from @jsprismarine/prismarine/modules/tokens.


getChunkCompletionQueue() ​

getChunkCompletionQueue(): ChunkCompletionQueue

Defined in: prismarine/src/Server.ts:781

The bounded queue for worker-result translation and background chunk lighting.

Returns ​

ChunkCompletionQueue


getChunkScheduler() ​

getChunkScheduler(): ChunkScheduler

Defined in: prismarine/src/Server.ts:776

Returns the world manager.

Returns ​

ChunkScheduler

The world manager.


getCommandManager() ​

getCommandManager(): CommandManager

Defined in: prismarine/src/Server.ts:760

Returns the command manager.

Returns ​

CommandManager

The command manager.


getConfig() ​

getConfig(): Config

Defined in: prismarine/src/Server.ts:1040

Returns the config.

Returns ​

Config

The config.

Example ​

typescript
console.log(server.getConfig().getMaxPlayers()); // 20

getConsole() ​

getConsole(): Console | undefined

Defined in: prismarine/src/Server.ts:1061

Returns the console instance.

Returns ​

Console | undefined

The console instance.


getConsoleSender() ​

getConsoleSender(): ConsoleSender

Defined in: prismarine/src/Server.ts:1070

Returns the sender the server speaks as in chat and command feedback.

Unlike getConsole, this is present on a headless server too.

Returns ​

ConsoleSender


getContent() ​

getContent(): ServerContent

Defined in: prismarine/src/Server.ts:819

Every content registry built from the pack stack.

Returns ​

ServerContent

The content.

Throws ​

When read before Server.enable has built it.


getContentWorld() ​

getContentWorld(): ServerWorldHandle

Defined in: prismarine/src/Server.ts:830

The world the content acts through, for the interaction path.

Returns ​

ServerWorldHandle

The handle.

Throws ​

When read before Server.enable has built it.


getCreativeInventory() ​

getCreativeInventory(): CreativeInventory

Defined in: prismarine/src/Server.ts:809

Returns this server's creative menu.

Returns ​

CreativeInventory

The menu, built from this server's own registries.


getDimensionTravel() ​

getDimensionTravel(): DimensionTravel

Defined in: prismarine/src/Server.ts:801

The portal travel service: where a trip through a portal lands and how an entity moves there.

Returns ​

DimensionTravel

The one instance shared by every world.


getEntityRuntime() ​

getEntityRuntime(dimension, level?): LiveEntityRuntime

Defined in: prismarine/src/Server.ts:856

The data-driven entities of one world.

Asking builds the world's content adapter if nothing has yet, so a world that loads after the content was built still gets a runtime.

Each level's dimension has its own: the runtime holds the store whose change log carries the world's block writes, and two levels each have an Overworld.

Parameters ​

dimension ​

string

The namespaced dimension identifier.

level? ​

string

The worlds.<name> level, left out for the default level.

Returns ​

LiveEntityRuntime

The runtime for that world.


getGenerationLimit() ​

getGenerationLimit(): number | undefined

Defined in: prismarine/src/Server.ts:1128

The background generation limit the governor currently asks for, when it is running.

Returns ​

number | undefined


getKernel() ​

getKernel(): Kernel<ServerEvents>

Defined in: prismarine/src/Server.ts:697

The module kernel the server runs on: the supported way to resolve the services the manager modules provide. Resolve a service with a token from modules/tokens, e.g. server.getKernel().get(bansToken).

Returns ​

Kernel<ServerEvents>

The kernel.


getLogger() ​

getLogger(): Logger

Defined in: prismarine/src/Server.ts:919

Returns the logger.

Returns ​

Logger

The logger.

Example ​

typescript
// Normal log:
server.getLogger().info('Hello, world!');
// Debug log:
server.getLogger().debug('Hello, world!');
// Error log:
server.getLogger().error(new Error('Hello World'));

getMetadata() ​

getMetadata(): ServerName

Defined in: prismarine/src/Server.ts:509

Returns ​

ServerName


getPacketHandlerRegistry() ​

getPacketHandlerRegistry(): PacketHandlerRegistry

Defined in: prismarine/src/Server.ts:994

Returns the packet registry.

Returns ​

PacketHandlerRegistry

The packet registry.


getPacketLogFilter() ​

getPacketLogFilter(): PacketLogFilter

Defined in: prismarine/src/Server.ts:1051

Which packets the traffic log leaves out, from log-excluded-packets.

Built once and kept: this is consulted for every packet in and out, and rebuilding the set each time would put a config read on the hot path.

Returns ​

PacketLogFilter

the filter.


getPermissionManager() ​

getPermissionManager(): PermissionManager

Defined in: prismarine/src/Server.ts:1080

Returns the permission manager.

Returns ​

PermissionManager

The permission manager.

Deprecated ​

Resolve it through the kernel instead: server.getKernel().get(permissionsToken), with permissionsToken from @jsprismarine/prismarine/modules/tokens.


getRaknet() ​

getRaknet(): RakNetListenerLike | undefined

Defined in: prismarine/src/Server.ts:1002

Returns the raknet instance.

Returns ​

RakNetListenerLike | undefined

The raknet instance.


getRandom() ​

getRandom(): Random

Defined in: prismarine/src/Server.ts:931

Where anything that rolls for something gets its chance from.

One source, reachable, rather than a Math.random() at each site: a drop table that is handed its randomness can be rolled ten thousand times in a test and checked against the odds it claims, and a plugin that wants a seeded server has somewhere to say so.

Returns ​

Random

the source of chance.


getReplayRandomState() ​

getReplayRandomState(): ServerReplayRandomState

Defined in: prismarine/src/Server.ts:936

Captures every stateful random stream the server keeps between ticks.

Returns ​

ServerReplayRandomState


getRespawnRequests() ​

getRespawnRequests(): RespawnRequests

Defined in: prismarine/src/Server.ts:1018

The respawn searches deaths filed, whose answers the next input step applies.

Returns ​

RespawnRequests

The requests.


getServer() ​

getServer(): Server

Defined in: prismarine/src/Server.ts:1098

Returns this Prismarine instance.

Returns ​

Server

The Prismarine instance.


getSessionManager() ​

getSessionManager(): SessionManager

Defined in: prismarine/src/Server.ts:768

Returns the player manager.

Returns ​

SessionManager

The player manager.


getStorePlayers() ​

getStorePlayers(): StorePlayers

Defined in: prismarine/src/Server.ts:870

The server's store players, by entity id, which every world's entity runtime shows and runs. A player is filed when its entity first enters a store and forgotten when it leaves the server.

Returns ​

StorePlayers

The store players.


getTick() ​

getTick(): number

Defined in: prismarine/src/Server.ts:1106

Returns the current Tick.

Returns ​

number

The current Tick.


getTickControl() ​

getTickControl(): TickControl

Defined in: prismarine/src/Server.ts:1150

The handle /tick uses to change the tick rate, freeze the world, step it and sprint.

Returns ​

TickControl


getTickMs() ​

getTickMs(): number

Defined in: prismarine/src/Server.ts:1123

Returns how long a tick's work has been taking, in milliseconds, as a moving average over the most recent ticks. It leaves out the sleep between ticks, so a healthy server reads well under the 50 ms period. Zero until the first tick completes.

Returns ​

number


getTickRecorder() ​

getTickRecorder(): TickRecorder

Defined in: prismarine/src/Server.ts:1133

The recent ticks' duration, lateness and phases.

Returns ​

TickRecorder


getTPS() ​

getTPS(): number

Defined in: prismarine/src/Server.ts:1114

Returns the current TPS.

Returns ​

number

The current TPS.


getVersion() ​

getVersion(): string

Defined in: prismarine/src/Server.ts:687

Returns the server version, the one the startup log prints.

Returns ​

string

The server version, without a leading v.

Example ​

typescript
console.log(server.getVersion());

getWorldManager() ​

getWorldManager(): WorldManager

Defined in: prismarine/src/Server.ts:793

Returns ​

WorldManager


getWorldMessages() ​

getWorldMessages(): WorldMessages

Defined in: prismarine/src/Server.ts:1010

The changes one world sends another, which the input step applies in the world each names.

Returns ​

WorldMessages

The messages.


getWorldReplicators() ​

getWorldReplicators(): WorldReplicators

Defined in: prismarine/src/Server.ts:789

The per-world replicators: what turns something happening in a world into packets.

Returns ​

WorldReplicators

The registry, which builds one per world on first use.


hasEntityRuntime() ​

hasEntityRuntime(): boolean

Defined in: prismarine/src/Server.ts:840

Whether Server.getEntityRuntime can answer, which it can once the pack stack is built: it builds a dimension's runtime on first ask.

Returns ​

boolean

Whether the content world exists.


hasListeners() ​

hasListeners(id): boolean

Defined in: prismarine/src/Server.ts:752

Whether a server event has at least one listener.

Parameters ​

id ​

keyof ServerEvents

The event.

Returns ​

boolean

Whether anything listens for it.


on() ​

on<K>(id, callback): this

Defined in: prismarine/src/Server.ts:709

Subscribes to a server event, on the kernel's event bus. Listeners run in the order they subscribed, and the same function subscribes to an event once. A listener that throws or rejects is logged and stops nothing.

Type Parameters ​

K ​

K extends keyof ServerEvents

Parameters ​

id ​

K

The event; see ServerEvents.

callback ​

EventListener<ServerEvents[K]>

Called with the event object each time the event is raised.

Returns ​

this

The server, for chaining.


once() ​

once<K>(id, callback): this

Defined in: prismarine/src/Server.ts:720

Subscribes to the next occurrence of a server event only. See Server.on.

Type Parameters ​

K ​

K extends keyof ServerEvents

Parameters ​

id ​

K

The event.

callback ​

EventListener<ServerEvents[K]>

Called with the event object once.

Returns ​

this

The server, for chaining.


releaseOnShutdown() ​

releaseOnShutdown(release): void

Defined in: prismarine/src/Server.ts:571

Registers something to undo the moment a shutdown begins.

For what the callers give up and why, see ShutdownLifecycle.releaseOnShutdown. A release runs once, synchronously, before the shutdown awaits anything - which is the whole point, as the teardown below may not get another turn of the event loop for seconds.

Parameters ​

release ​

() => void

Gives up whatever is keeping the kernel from killing this process.

Returns ​

void


reload() ​

reload(): Promise<void>

Defined in: prismarine/src/Server.ts:521

Reloads the server.

Returns ​

Promise<void>

A promise that resolves when the server is reloaded.

Remarks ​

This method is equivalent to calling Server#disable and Server#enable.


removeAllListeners() ​

removeAllListeners(id?): this

Defined in: prismarine/src/Server.ts:742

Removes the listeners Server.on and Server.once subscribed, to one event or to all of them. The server's own modules keep theirs.

Parameters ​

id? ​

keyof ServerEvents

The event, or every event when omitted.

Returns ​

this

The server, for chaining.


removeListener() ​

removeListener<K>(id, callback): this

Defined in: prismarine/src/Server.ts:731

Removes a listener that Server.on or Server.once subscribed.

Type Parameters ​

K ​

K extends keyof ServerEvents

Parameters ​

id ​

K

The event.

callback ​

EventListener<ServerEvents[K]>

The listener as it was subscribed.

Returns ​

this

The server, for chaining.


restoreReplayRandomState() ​

restoreReplayRandomState(state): void

Defined in: prismarine/src/Server.ts:953

Restores the saved random streams without changing any draw sites or their order.

Parameters ​

state ​

unknown

Returns ​

void


setContent() ​

setContent(content): void

Defined in: prismarine/src/Server.ts:899

Replaces the content registries.

For a test and for a plugin that composes its own stack. Hands over a whole build, not a patch: a registry's numeric ids are positional, so a half-replaced content set would leave the flattened tables indexed against a palette that no longer matches.

Parameters ​

content ​

ServerContent

The build to run on from here.

Returns ​

void


setRandom() ​

setRandom(random): void

Defined in: prismarine/src/Server.ts:985

Replaces the source of chance.

Parameters ​

random ​

Random

what to roll with from now on.

Returns ​

void


shutdown() ​

shutdown(options?): Promise<void>

Defined in: prismarine/src/Server.ts:584

Kills the server asynchronously.

Asking twice forces the exit rather than returning - see ShutdownLifecycle.forceExit.

Parameters ​

options? ​

The options.

crash? ​

boolean

If the server should crash.

stayAlive? ​

boolean

If we should let the process stay alive.

Returns ​

Promise<void>

A promise that resolves when the server is killed.