Skip to content

ServerScriptObject

This interface wraps auto-mcs’s ServerObject to expose the server configuration (including server.properties), connected players, lifecycle commands, messaging, timers, and persistent data. Access it through the global server keyword.

View the source: ServerScriptObject · ServerObject

Immediately starts the server if it’s not running

Immediately stops the server

Immediately stops and restarts the server

Sends a custom log event to the console. This output is displayed only while the server is running, and is not saved to latest.log

  • server.log_success(), server.log_warning(), and server.log_error() methods can also be used for automatic formatting, and only require the message parameter
ParametersTypeDescription
message*strThe content to log
log_typestrAccepts 'info', 'success', 'warning' or 'error'. Defaults to 'info'

server.broadcast(message, color="gray", style="italic", hyperlink=None)

Section titled “server.broadcast(message, color="gray", style="italic", hyperlink=None)”

Sends a custom chat message to all players and the console. This output is displayed only while the server is running, and is not saved to latest.log

  • server.broadcast_success(), server.broadcast_warning(), and server.broadcast_error() methods can also be used, and only require the message parameter
ParametersTypeDescription
message*strThe content to broadcast
colorstrMinecraft color ID, all values for /tellraw are accepted; see all color IDs
stylestrCan be 'normal', 'italic', 'bold', 'strikethrough', 'underlined', or 'obfuscated'. Defaults to 'italic'
hyperlinkstrURL to make the message a clickable hyperlink (1.7.2+)

server.operator_broadcast(message, color="gray", style="italic", hyperlink=None)

Section titled “server.operator_broadcast(message, color="gray", style="italic", hyperlink=None)”

Sends a custom chat message to all operators and the console. This output is displayed only while the server is running, and is not saved to latest.log

ParametersTypeDescription
message*strThe content to broadcast
colorstrMinecraft color ID, all values for /tellraw are accepted; see all color IDs
stylestrCan be 'normal', 'italic', 'bold', 'strikethrough', 'underlined', or 'obfuscated'. Defaults to 'italic'
hyperlinkstrURL to make the message a clickable hyperlink (1.7.2+)

Executes any Minecraft command in the server console

ParametersTypeDescription
command*strAny Minecraft command; see a list of all commands
logboolShow EXEC line in the Console. Defaults to False

server.after(delay, function, *args, **kwargs)

Section titled “server.after(delay, function, *args, **kwargs)”

Runs a delayed background (non-blocking) task. Exits before execution if the server stops, or if scripts are reloaded. Returns an instance of AmsTimer of the background task. AmsTimer.cancel() can be used to end the timer prematurely without execution

ParametersTypeDescription
delay*int / floatDelay in seconds
function*callableAny Python callable function or method
argstuplePositional arguments passed to function
kwargsdictKeyword arguments passed to function

Returns a matching PlayerScriptObject, or None. The special selector @a returns server.get_players()

ParametersTypeDescription
tag*strUsername, or a selector for a single player such as @p, @r, or @a[limit=1]; see a list of all selectors
offlineboolRetrieves playerdata from .dat file if the target player isn’t connected to the server. Defaults to False

Returns a generator of PlayerScriptObject for each online player

Internal method to restart the amscript engine runtime

AttributeTypeDescription
server.namestrServer’s current filename
server.versionAmsVersionMinecraft version of the server, i.e. 1.16.3. When used in a string, it will be formatted as '1.16.3'. Can be compared with version strings
server.buildstr / NoneApplicable to server types with build numbers. Otherwise, None
server.typestrNormalized server type; can be 'vanilla', 'craftbukkit', 'spigot', 'paper', 'purpur', 'forge', 'neoforge', 'fabric', or 'quilt'
server.worldstrFilename of level-name from server.properties
server.directorystrFull path of the directory in which the server is stored
server.networkMunchDict-like structure containing the listening IP and port; Structured as {'ip': str, 'port': int}; can be accessed as server.network.ip and server.network.port
server.uptimetimedelta / NoneDelta since launch, or None if the server has not yet started
server.is_readyboolTrue when the server’s game loop has started and is ready for players to join
server.propertiesdictKey & value pairs in the server.properties file; a boolean value for example can be accessed with server.properties['enable-command-block']
server.player_listdictContains a key and a sub-dictionary for each connected player; {username: {'uuid': str, 'ip': str, 'date': datetime, 'logged-in': bool}}
server.usercachedictContains a dictionary for each player who has ever joined the server; The current format is {username: uuid}
server.persistentdictPersistent variable storage for saving server-specific data between server restarts, or script reloads; assigning or updating a key retains it in the engine’s persistent state until changed or deleted. This data is scoped to this server, and does not persist between different servers
server.libs_pathstrFull filesystem path to amscript’s external libraries
server.util_pathstrFull filesystem path to amscript’s external binaries
server.ams_versionstrContains the current amscript version to account for API changes
server.outputlistContains a formatted list of dictionaries organizing the items visible in the auto-mcs console from oldest to newest (limit of 850). See the example below
server.aliasesdictRegistered @player.on_alias commands keyed by !command; includes syntax, permission, description, and source. Hidden aliases are excluded

server.output example:

[
# ...earlier output omitted...
{'text': (' 1:43:03 PM', 'INFO', 'Starting Minecraft server on *:25565', (0.6, 0.6, 1, 1))},
{'text': (' 1:43:03 PM', 'INFO', 'Preparing level "world"', (0.6, 0.6, 1, 1))},
{'text': (' 1:43:05 PM', 'INFO', 'Loading 0 persistent chunks...', (0.6, 0.6, 1, 1))},
{'text': (' 1:43:05 PM', 'INFO', 'Preparing spawn area: [/////////////////////////] 100%', (0.6, 0.6, 1, 1))},
{'text': (' 1:43:05 PM', 'INFO', 'Time elapsed: 38 ms', (0.6, 0.6, 1, 1))},
{'text': (' 1:43:05 PM', 'START', 'Done (1.899s)! For help, type "help". Type "!help" for auto-mcs commands', (0.3, 1, 0.6, 1))}
]
server.output[-1]['text'][2]
>>> 'Done (1.899s)! For help, type "help". Type "!help" for auto-mcs commands'