Sub-servers
Move players between your server's sub-servers, and create, start and stop them from a script.
What a sub-server is
A server on Play Strawberry can have sub-servers: other servers of the same account that belong to it, for example a lobby on the main server and the game itself on a sub-server.
- A sub-server has no address of its own. Players reach it only through a move that a script asks for. A player who comes any other way is refused with "Join through" and the main server's address.
- A moved player keeps their login and does not see the login form again.
- How many sub-servers a server may have depends on its plan. A script never buys a place.
The permission
Everything on this page needs the script permission platform.sub-servers. The server owner sees it when they install the script, like the other platform permissions. Without it every job answers no-permission, list() is empty, places() is (0, 0) and the event readers answer None.
// in your plugin's metadata()
permissions: vec![strawberry_plugin_api::permissions::PLATFORM_SUB_SERVERS.into()],Read the group
sub_servers::this_server(): this server, withid,name,role(MainorSub),state,playersandmax_players.sub_servers::list(): every server of the group, this one included.sub_servers::places():(used, total), the sub-server places in use and the places the plan gives.
These answer at once. They show Play Strawberry's latest answer, which the server asks for again every 10 seconds and after each job. state is one of Stopped, Starting, Running, Stopping and Crashed.
Move players
use strawberry_plugin_api::sub_servers as subs;
let game = subs::list()
.into_iter()
.find(|s| s.name == "Game" && s.state == subs::State::Running);
if let Some(game) = game {
let job = subs::move_players(&party, Some(game.id.as_str()), Some(br#"{"mode":"duo"}"#.as_slice()));
// keep `job` and call `job.poll()` from a task: `None` while it runs
}move_players(players, to, data) takes:
players: the ids of players online on this server, up to 100. They move together.to: the id of a server of this group, orNonefor the main server.data: up to 3 KiB that arrives with each player on the target.
A move goes in three steps:
- Every player is checked and a seat is held on the target for each, for all of them or for none. If one cannot go, nobody moves and the job says why.
- Each player is transferred. A player whose transfer cannot be sent at this step is disconnected and fires
sub-server-move-failed; the others still go. - On the target,
sub-server-player-arrivedfires once for each player who joins within 30 seconds of the transfer.
Poll the MoveJob: Some(Ok(players)) lists the players who were sent, and Some(Err(refusal)) says why nobody was. A transfer that was sent is not an arrival. To start a match only with the whole party, send a match id and the expected players in data, and start on the target when all of them arrived, or after a deadline of your own.
Java and Bedrock players are moved by the same call. Where Play Strawberry cannot move a Bedrock player, the whole move is refused with Bedrock; there is nothing a script or a server owner can switch on. A connection check on the target can read the source server and the data of a Bedrock move before it admits the player, with sub_servers::checked_bedrock_handoff(connection).
A sub-server that stops, for any reason, first moves its players to the main server.
One account, one server
An account is online on only one server of the group at a time. A move takes the player's place along, and the server they leave ends their session at once. A second login of the same account on another server of the group is refused with "This account is already online." While the server cannot check this, a login is refused and the player is asked to try again in a moment.
Players a lobby moves together all get in, even when they share one internet connection. Anyone who reconnects again and again within a few seconds is told to wait, as on Paper.
Create, start and stop a sub-server
sub_servers::create_server(&spec)makes a new sub-server in a free place. The spec hasname(1 to 32 characters),template(a template published withpublish_template_job, orNonefor a new world),plugins(None: the same as this server's) andmax_players(None: the plan's default). The same spec asked for twice while the first one runs makes one server.sub_servers::start_server(id)starts the sub-serverid.sub_servers::stop_server(id)stops it. Its players go to the main server first.
Each returns a ServerJob. poll() gives None while it runs, then the server as it is, or a refusal. Creating a server takes minutes, not ticks. A script cannot start or stop the main server.
A sub-server made from a template takes in the saved world at its first start: its terrain, its Nether and End, its saved data and its data packs. The players' inventories, ender chests and advancements are never copied. If the copy is damaged, the sub-server does not start and its console says why.
Refusals
NoPermission: the script lacksplatform.sub-servers.NoPlace: no free sub-server place on the plan, or a spec that cannot be a server (an empty or too long name).UnknownServer: not a server of this group; for start and stop, also the main server.NotRunning: the target is not running.Full: the target has no room for all of the players.Offline: a player is not on this server, left during the move, or Play Strawberry did not confirm the player's place.Bedrock: a Bedrock player Play Strawberry cannot move.OtherProtocol: a Java player whose client is not on the server's version.NotAdmitted: a player the login gate has not admitted on this visit.TooMuchData:datais over 3 KiB.Busy: a move of this player is already on its way, or the script has 4 jobs on their way or started 30 in the last minute. Try again later.NoAnswer: Play Strawberry did not answer. Try again later.
Events
All three are extension events and observers: they report what happened, cannot be cancelled and never hold up the server.
sub-server-player-arrivedfires on the target, after the join. Read it withcontext.on_sub_server_arrived(|player, from, data| ...)orsub_servers::arrival(event).sub-server-move-failedfires on the server that asked for the move. Read it withcontext.on_sub_server_move_failed(|player, why| ...)orsub_servers::move_failure(event).sub-server-statefires on every server of the group when a server started, stopped or crashed. Read it withcontext.on_sub_server_state(|server| ...)orsub_servers::state_change(event).
fn on_load(&self, ctx: Context) -> Result<()> {
ctx.on_sub_server_arrived(|player, from, data| start_run(player, from, data))?;
ctx.on_sub_server_move_failed(|player, why| keep_in_lobby(player, why))?;
Ok(())
}Transfers, cookies and packet hooks
A packet hook never sees a move between a group's servers. A transfer that a script or /transfer starts with player.transfer (a transfer to any address, as on Paper) is visible to hooks, as on Paper.
send_packet sends a Java player the cookie packets: store a cookie on the client (c-store-cookie in play, config-c-store-cookie in configuration) or ask for one (c-play-cookie-request, config-c-cookie-request). Cookies stay on the client between servers, so a lobby can store a small ticket and the game server can read it after a transfer.
- A cookie holds at most 5 KiB (5120 bytes), as in the vanilla game.
- A larger cookie, or a key the game cannot read, is not sent and the call fails with an error that names the packet and the size. Use lower-case letters, digits and
_ - . /, likemyplugin:ticket. - Keys in the
strawberry:namespace belong to the server and are never sent by a script.
transfer, transfer_labeled and transfer_checked send a Bedrock player to the same host name a Java player gets (<name>.playstrawberry.net), on the Bedrock gateway's port (19132) instead of the Java port you pass. No separate Bedrock host name exists. A host that is not <name>.playstrawberry.net (one DNS label), including any *.bedrock.playstrawberry.net name, is not sent anything: transfer_checked answers BedrockHost, or Bedrock when there is no gateway port.
Friends in your game
A lobby can show "Join a friend" with two calls. Both need the permission platform.friends and are jobs: poll them until they answer, and ask when the page opens or the player clicks, not every tick.
friends::friends_here(viewer, reads)lists the player's Play Strawberry friends who are playing your game, on this server or on another server of its group. Each comes with a name, a status, whether the player may join them, the server and the session they are in (friends in the same session play together), and the values of up to four shared player-data keys your game wrote for them, for example a keystopholding "Level 37". Reading keys needs the permissionplatform.player-dataand the same rules asplayer_data::get_from.friends::join_friend(viewer, friend)is Play Strawberry's Join friend: the platform decides and holds the seats, then the server moves the player there. Players who joined together move together, so a party is never split.
The list is exactly what Play Strawberry shows to that player: a friend who hides their activity, blocks the player or is outside the game's age limit is not listed. Build the picker as a full-screen page (pages/<name>.json, see Menus and screens); it works on Java and Bedrock.
Player data across the group
Play Strawberry keeps small values per player for the servers of one game, so a player's progress follows them across the group (player_data, see player-data). Only players with a linked Play Strawberry account have data. For anyone else a call answers NotReady, so keep your script working without it.