There are multiple ways to get servers from the API:
// Get all serversval allServers = controllerApi.getServers().getAllServers()// Get server by IDval server = controllerApi.getServers().getServerById("server-uuid")// Get servers by group nameval lobbyServers = controllerApi.getServers().getServersByGroup("lobby")// Get server by group name and numerical IDval specificServer = controllerApi.getServers().getServerByNumerical("lobby", 1)// Get servers by typeval proxyServers = controllerApi.getServers().getServersByType(ServerType.PROXY)
You can start a new server by specifying the group name and optionally a start cause:
// Start a server with default causeval server = controllerApi.getServers().startServer("lobby")// Start a server with specific causeval server = controllerApi.getServers().startServer( groupName = "lobby", startCause = ServerStartCause.API_START)
// Stop a server by IDcontrollerApi.getServers().stopServer( id = "server-uuid", stopCause = ServerStopCause.API_STOP)// Stop a server by group and numerical IDcontrollerApi.getServers().stopServer( groupName = "lobby", numericalId = 1, stopCause = ServerStopCause.API_STOP)// Stop all servers in a groupcontrollerApi.getServers().stopServers( groupName = "lobby", stopCause = ServerStopCause.API_STOP)// Stop all servers in a group with timeoutcontrollerApi.getServers().stopServers( groupName = "lobby", timeoutSeconds = 60, stopCause = ServerStopCause.API_STOP)
There are several ways to update server properties:
// Update entire server objectval updatedServer = controllerApi.getServers().updateServer(server)// Update server stateval updatedServer = controllerApi.getServers().updateServerState( id = "server-uuid", state = ServerState.STARTING)// Update a single propertyval updatedServer = controllerApi.getServers().updateServerProperty( id = "server-uuid", key = "maxPlayers", value = 200)
You can use the getCurrentServer() method to get information about the current server:
val currentServer = controllerApi.getServers().getCurrentServer()println("Current server group: ${currentServer.group}")println("Current server ID: ${currentServer.uniqueId}")
SimpleCloud automatically provides environment variables that you can access without initializing the API. These variables are available in two categories:
Any custom properties defined in your group configuration are automatically available as environment variables. The property names are:
Prefixed with SIMPLECLOUD_
Converted to uppercase
Have dashes (-) replaced with underscores (_)
For example:
// In your group configurationval group = Group( name = "lobby", properties = mapOf( "game-mode" to "ADVENTURE", "isLobby" to "true", "max_rounds" to "5" ))// In your server codeval gameMode = System.getenv("SIMPLECLOUD_GAME_MODE") // Returns "ADVENTURE"val isLobby = System.getenv("SIMPLECLOUD_ISLOBBY") // Returns "true"val maxRounds = System.getenv("SIMPLECLOUD_MAX_ROUNDS") // Returns "5"