Skip to content

Server Events

Fired upon process execution by auto-mcs, not when the game loop has opened

ParametersTypeDescription
data*dict{'date': datetime, 'restart': bool}
delayint / floatWait before running the block, in seconds
@server.on_start(data, delay=0):
if data['restart']: server.log("Server has restarted!")
else: server.log("Server has started!")

Fired when the game loop is opened, or rather, when players can connect and commands can be executed. The server’s status can also be polled by using server.is_ready

ParametersTypeDescription
data*dict{'date': datetime}
delayint / floatWait before running the block, in seconds
@server.on_ready(data, delay=0):
server.execute('/time set 0')

Fired upon process termination by auto-mcs, not when /stop or a crash is logged

ParametersTypeDescription
data*dict{'date': datetime, 'crash': str | None, 'restart': bool}
delayint / floatWait before running the block, in seconds
@server.on_stop(data, delay=0):
if data['crash']: server.log("Server has crashed :P")
else: server.log("Server has stopped!")

This event is also fired when the amscript engine is reloaded.

Since engine restarts create a new memory space, this is useful when an asynchronous task such as a GUI window or another server is running in the background, and that process needs to be closed when scripts are reloaded or the server is stopped.

This example demonstrates how to implement a Tkinter UI that will close and re-open when the engine is restarted:

import tkinter as tk
window = tk.Tk()
@server.on_start(data):
window.mainloop()
@server.on_stop(data):
window.destroy()

Repeatedly invokes the event block at the specified interval until the server stops, the engine reloads, or the block executes return to end the loop

ParametersTypeDescription
intervalintDefaults to 1
unitstrinterval scale; can be 'tick', 'second', 'minute', or 'hour'. Defaults to 'second'
@server.on_loop(interval=1, unit='minute'):
server.execute("/kill @e[type=item]")
server.log_success("Cleaned up items!")

Fired when a console line from the server process is emitted.

ParametersTypeDescription
datedatetimeTime at which the line was emitted
levelstrConsole log level; can be 'start', 'stop', 'player', 'exec', 'chat', 'info', 'warn', 'error', 'severe', 'fatal'
linestrMessage content of the line emitted
delayint / floatWait before running the block, in seconds
@server.on_output(date, level, line):
if "preparing spawn area" in line.lower():
server.log("Spawn preparation detected")