Server Events
@server.on_start
Section titled “@server.on_start”Fired upon process execution by auto-mcs, not when the game loop has opened
| Parameters | Type | Description |
|---|---|---|
data* | dict | {'date': datetime, 'restart': bool} |
delay | int / float | Wait 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!")@server.on_ready
Section titled “@server.on_ready”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
| Parameters | Type | Description |
|---|---|---|
data* | dict | {'date': datetime} |
delay | int / float | Wait before running the block, in seconds |
@server.on_ready(data, delay=0): server.execute('/time set 0')@server.on_stop
Section titled “@server.on_stop”Fired upon process termination by auto-mcs, not when /stop or a crash is logged
| Parameters | Type | Description |
|---|---|---|
data* | dict | {'date': datetime, 'crash': str | None, 'restart': bool} |
delay | int / float | Wait 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 tkwindow = tk.Tk()
@server.on_start(data): window.mainloop()
@server.on_stop(data): window.destroy()@server.on_loop
Section titled “@server.on_loop”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
| Parameters | Type | Description |
|---|---|---|
interval | int | Defaults to 1 |
unit | str | interval 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!")@server.on_output
Section titled “@server.on_output”Fired when a console line from the server process is emitted.
| Parameters | Type | Description |
|---|---|---|
date | datetime | Time at which the line was emitted |
level | str | Console log level; can be 'start', 'stop', 'player', 'exec', 'chat', 'info', 'warn', 'error', 'severe', 'fatal' |
line | str | Message content of the line emitted |
delay | int / float | Wait before running the block, in seconds |
@server.on_output(date, level, line): if "preparing spawn area" in line.lower(): server.log("Spawn preparation detected")