@@ -103,22 +103,49 @@ CB has a public API module for other plugins to interact with the bridge network
103103``` java
104104CommandBridgeAPI api = CommandBridgeProvider . get();
105105
106- // send a command as console to a backend
107- CommandChannel commands = api. channel(Channels . COMMAND );
108- commands. console(Platform . BACKEND. target(" survival-1" ), " say hello" );
106+ // get a typed message channel
107+ MessageChannel<CommandPayload > commands = api. channel(Channels . COMMAND );
109108
110- // listen for incoming messages
111- Subscription sub = commands. listen((ctx, payload) - > { /* ... */ } );
109+ // send a command as console to a specific backend
110+ commands. send( Platform . BACKEND . target( " survival-1 " ), CommandPayload . console( " say hello " ) );
112111
113- // server events
114- api. onServerConnected(server - > { /* ... */ });
115- api. onServerDisconnected(server - > { /* ... */ });
112+ // send a command as a player
113+ commands. send(Platform . BACKEND. target(" survival-1" ), CommandPayload . player(" spawn" , playerUuid));
116114
117- // find a player across the network
118- api . playerLocator() . ifPresent(locator - > locator . locate(playerUuid ));
115+ // broadcast a command to all connected servers
116+ commands . broadcast( CommandPayload . console( " say maintenance in 5 minutes " ));
119117
120- // broadcast to all servers
121- api. broadcast(commands, CommandPayload . console(" say maintenance in 5 minutes" ));
118+ // request-response (waits for the target to reply)
119+ commands. request(Platform . BACKEND. target(" survival-1" ), CommandPayload . console(" list" ))
120+ .thenAccept(response - > { /* handle response */ });
121+
122+ // listen for incoming messages on this channel
123+ Subscription sub = commands. listen((ctx, payload) - > {
124+ Platform . ServerTarget from = ctx. from();
125+ String command = payload. command();
126+ });
127+ sub. cancel(); // unsubscribe when done
128+
129+ // server lifecycle events
130+ api. onServerConnected(server - > { /* server joined the network */ });
131+ api. onServerDisconnected(server - > { /* server left the network */ });
132+
133+ // connection state monitoring
134+ api. onConnectionStateChanged(state - > {
135+ if (state. canSend()) { /* ready to send messages */ }
136+ });
137+
138+ // current server identity and state
139+ Platform . ServerTarget self = api. server();
140+ ConnectionState state = api. connectionState();
141+
142+ // list all connected servers (available on velocity)
143+ api. connectedServers(). ifPresent(servers - > { /* Set<String> of server IDs */ });
144+
145+ // find which server a player is on (available on velocity)
146+ api. playerLocator(). ifPresent(locator - >
147+ locator. locate(playerUuid). ifPresent(server - > { /* player is on this server */ })
148+ );
122149```
123150
124151---
0 commit comments