Skip to content

Commit ad03680

Browse files
committed
docs(api): scope each type's JavaDoc examples to its own responsibility
1 parent 3d7ad09 commit ad03680

8 files changed

Lines changed: 56 additions & 157 deletions

File tree

api/src/main/java/dev/objz/commandbridge/api/CommandBridgeAPI.java

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,17 @@
1717
* third-party plugin.
1818
*
1919
* <p>
20-
* Use {@link #channel(Class)} to obtain typed message channels for sending and
21-
* receiving
22-
* payloads. {@link #server()} and {@link #connectionState()} expose the current
23-
* server's identity
24-
* and connection status. {@link #connectedServers()}, {@link #playerLocator()},
25-
* {@link #onServerConnected(ServerEventListener)}, and
26-
* {@link #onServerDisconnected(ServerEventListener)} are available only on the
27-
* Velocity proxy;
28-
* they return {@code Optional.empty()} on backend servers.
20+
* Obtain an instance via {@link CommandBridgeProvider#get()}.
21+
* Use {@link #channel(Class)} to obtain typed message channels,
22+
* {@link #server()} and {@link #connectionState()} to query the current
23+
* server's identity and connection status, and
24+
* {@link #onServerConnected(ServerEventListener)} or
25+
* {@link #onServerDisconnected(ServerEventListener)} to subscribe to
26+
* server lifecycle events on the Velocity proxy.
2927
*
3028
* <p>
31-
* Obtain an instance via {@link CommandBridgeProvider#get()} and use
32-
* {@link #channel(Class)}
33-
* to build a typed message channel:
34-
*
35-
* <pre>{@code
36-
* CommandBridgeAPI api = CommandBridgeProvider.get();
37-
* MessageChannel<CommandPayload> channel = api.channel(CommandPayload.class);
38-
* }</pre>
39-
*
40-
* <p>
41-
* To send a command to a specific backend server:
42-
*
43-
* <pre>{@code
44-
* channel.to(List.of(Platform.backend("survival-1")))
45-
* .send(new CommandPayload("say hello", RunAs.CONSOLE));
46-
* }</pre>
47-
*
48-
* <p>
49-
* To broadcast a command to every connected server:
50-
*
51-
* <pre>{@code
52-
* channel.toAll().send(new CommandPayload("say maintenance soon", RunAs.CONSOLE));
53-
* }</pre>
54-
*
55-
* <p>
56-
* To receive a notification when a backend server connects (Velocity proxy
57-
* only):
58-
*
59-
* <pre>{@code
60-
* api.onServerConnected(server -> System.out.println("Connected: " + server.id())).ifPresent(subscriptions::add);
61-
* }</pre>
62-
*
63-
* <p>
64-
* To track connection state transitions on any platform:
65-
*
66-
* <pre>{@code
67-
* api.onConnectionStateChanged(state -> {
68-
* if (state.isActive()) {
69-
* // ready to send
70-
* }
71-
* });
72-
* }</pre>
29+
* Methods returning {@link java.util.Optional} are available only on the
30+
* Velocity proxy and return {@code Optional.empty()} on backend servers.
7331
*
7432
* @see CommandBridgeProvider
7533
* @see dev.objz.commandbridge.api.channel.MessageChannel

api/src/main/java/dev/objz/commandbridge/api/channel/ChannelPayload.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,16 @@
77
* <p>
88
* Implementing this interface registers a type as a valid payload. The
99
* {@link dev.objz.commandbridge.api.channel.MessageChannel} uses the payload's
10-
* {@code Class}
11-
* token for channel routing and type-safe dispatch.
10+
* {@code Class} token for channel routing and type-safe dispatch.
1211
*
1312
* <p>
1413
* {@link dev.objz.commandbridge.api.channel.command.CommandPayload} is the
15-
* built-in
16-
* implementation for command execution. Custom payload types can be created by
17-
* implementing
18-
* this interface and using them with
19-
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#channel(Class)}.
14+
* built-in implementation for command execution. Custom payload types can be
15+
* created by implementing this interface:
2016
*
21-
* <p>
22-
* Example of a custom payload type:
23-
*
2417
* <pre>{@code
2518
* public record MyPayload(String data) implements ChannelPayload {
2619
* }
27-
*
28-
* MessageChannel<MyPayload> channel = api.channel(MyPayload.class);
29-
* channel.toAll().send(new MyPayload("hello"));
3020
* }</pre>
3121
*
3222
* @see dev.objz.commandbridge.api.channel.command.CommandPayload

api/src/main/java/dev/objz/commandbridge/api/channel/MessageChannel.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,36 @@
1515
*
1616
* <p>
1717
* A {@code MessageChannel} is bound to a specific payload type {@code P},
18-
* providing type-safe
19-
* message routing. Obtain an instance via
20-
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#channel(Class)}.
21-
* Target one or more servers with {@link #to(java.util.Collection)} or
22-
* broadcast to all connected
23-
* servers with {@link #toAll()}. Subscribe to incoming messages with
18+
* providing type-safe message routing. Target one or more servers with
19+
* {@link #to(java.util.Collection)}, broadcast to all connected servers with
20+
* {@link #toAll()}, or subscribe to incoming messages with
2421
* {@link #listen(dev.objz.commandbridge.api.message.MessageListener)}.
2522
*
2623
* <p>
27-
* All send operations return {@link java.util.concurrent.CompletableFuture} and
28-
* are
29-
* non-blocking.
24+
* All send operations return {@link java.util.concurrent.CompletableFuture}
25+
* and are non-blocking.
3026
*
3127
* <p>
32-
* To obtain a channel and send a command to a specific backend server:
28+
* To send a payload to a specific server:
3329
*
3430
* <pre>{@code
35-
* CommandBridgeAPI api = CommandBridgeProvider.get();
36-
* MessageChannel<CommandPayload> channel = api.channel(CommandPayload.class);
3731
* channel.to(List.of(Platform.backend("survival-1")))
38-
* .send(new CommandPayload("say hello", RunAs.CONSOLE));
32+
* .send(payload);
3933
* }</pre>
4034
*
4135
* <p>
42-
* To broadcast a command to every connected server:
36+
* To broadcast to every connected server:
4337
*
4438
* <pre>{@code
45-
* channel.toAll().send(new CommandPayload("say maintenance soon", RunAs.CONSOLE));
39+
* channel.toAll().send(payload);
4640
* }</pre>
4741
*
4842
* <p>
49-
* To receive incoming messages on this channel, register a listener and cancel
50-
* it when done:
43+
* To subscribe to incoming messages and cancel the listener later:
5144
*
5245
* <pre>{@code
53-
* Subscription sub = channel
54-
* .listen((ctx, payload) -> System.out.println("Command from " + ctx.from().id() + ": " + payload.command()));
46+
* Subscription sub = channel.listen((ctx, payload) ->
47+
* System.out.println("From " + ctx.from().id()));
5548
* sub.cancel();
5649
* }</pre>
5750
*

api/src/main/java/dev/objz/commandbridge/api/channel/command/CommandPayload.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,35 @@
1010
*
1111
* <p>
1212
* The three components define what to run and how. {@code command} is the
13-
* command string
14-
* without a leading slash. {@code runAs} defines the execution context; see
15-
* {@link RunAs} for
16-
* available modes. {@code player} is the optional player UUID required when
17-
* {@code runAs} is
18-
* {@link RunAs#PLAYER} or {@link RunAs#OPERATOR}; pass {@code null} for
19-
* {@link RunAs#CONSOLE}.
13+
* command string without a leading slash. {@code runAs} defines the execution
14+
* context; see {@link RunAs} for available modes. {@code player} is the
15+
* optional player UUID required when {@code runAs} is {@link RunAs#PLAYER}
16+
* or {@link RunAs#OPERATOR}; pass {@code null} for {@link RunAs#CONSOLE}.
2017
*
2118
* <p>
2219
* Instances are sent through a
2320
* {@link dev.objz.commandbridge.api.channel.MessageChannel} obtained from
2421
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#channel(Class)}.
2522
*
2623
* <p>
27-
* To run a command as the server console on a specific backend server:
24+
* To create a console command with no player context:
2825
*
2926
* <pre>{@code
30-
* MessageChannel<CommandPayload> channel = api.channel(CommandPayload.class);
31-
* channel.to(List.of(Platform.backend("survival-1")))
32-
* .send(new CommandPayload("say hello", RunAs.CONSOLE));
27+
* new CommandPayload("say hello", RunAs.CONSOLE)
3328
* }</pre>
3429
*
3530
* <p>
36-
* To run a command as a specific online player with their normal permissions:
31+
* To create a command that runs as a specific player:
3732
*
3833
* <pre>{@code
39-
* channel.to(List.of(Platform.backend("survival-1")))
40-
* .send(new CommandPayload("home", RunAs.PLAYER, playerUUID));
34+
* new CommandPayload("home", RunAs.PLAYER, playerUUID)
4135
* }</pre>
4236
*
4337
* <p>
44-
* To run a command as a player with temporary operator-level permissions:
38+
* To create a command with temporary operator permissions:
4539
*
4640
* <pre>{@code
47-
* channel.to(List.of(Platform.backend("survival-1")))
48-
* .send(new CommandPayload("gamemode creative", RunAs.OPERATOR, playerUUID));
41+
* new CommandPayload("gamemode creative", RunAs.OPERATOR, playerUUID)
4942
* }</pre>
5043
*
5144
* @param command the command string to execute on the target server; must not

api/src/main/java/dev/objz/commandbridge/api/message/MessageListener.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,19 @@
88
*
99
* <p>
1010
* This is a {@code @FunctionalInterface} and may be used as a lambda
11-
* expression.
12-
* Register an instance via
11+
* expression. Register an instance via
1312
* {@link dev.objz.commandbridge.api.channel.MessageChannel#listen(MessageListener)},
1413
* which returns a {@link dev.objz.commandbridge.api.message.Subscription} that
15-
* can be
16-
* used to cancel the listener.
14+
* can be used to cancel the listener.
1715
*
1816
* <p>
19-
* To register a listener as a lambda and retain the returned
20-
* {@link Subscription}:
17+
* The listener receives the message metadata and the deserialized payload:
2118
*
2219
* <pre>{@code
23-
* MessageChannel<CommandPayload> channel = api.channel(CommandPayload.class);
24-
*
25-
* Subscription sub = channel.listen((ctx, payload) -> {
20+
* (ctx, payload) -> {
2621
* String from = ctx.from().id();
27-
* String command = payload.command();
28-
* });
29-
* }</pre>
30-
*
31-
* <p>
32-
* Pass the subscription to {@link Subscription#cancel()} to stop receiving
33-
* messages:
34-
*
35-
* <pre>{@code
36-
* sub.cancel();
22+
* long sentAt = ctx.timestamp();
23+
* }
3724
* }</pre>
3825
*
3926
* @param <T> the type of payload this listener handles;

api/src/main/java/dev/objz/commandbridge/api/message/ServerEventListener.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
*
99
* <p>
1010
* This is a {@code @FunctionalInterface} and may be used as a lambda
11-
* expression. Register
12-
* listeners via
11+
* expression. Register listeners via
1312
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#onServerConnected(ServerEventListener)}
1413
* and
1514
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#onServerDisconnected(ServerEventListener)}.
1615
* Both methods return an {@link java.util.Optional} wrapping a
17-
* {@link dev.objz.commandbridge.api.message.Subscription}
18-
* on the Velocity proxy, and {@code Optional.empty()} on backend servers.
16+
* {@link dev.objz.commandbridge.api.message.Subscription} on the Velocity
17+
* proxy, and {@code Optional.empty()} on backend servers.
18+
*
19+
* <p>
20+
* The listener receives the server that triggered the event:
1921
*
2022
* <pre>{@code
21-
* api.onServerConnected(server -> Log.info("Server connected: {}", server.id())).ifPresent(subscriptions::add);
23+
* server -> Log.info("Server {}: {}", server.id(), server.type())
2224
* }</pre>
2325
*
2426
* @see dev.objz.commandbridge.api.CommandBridgeAPI#onServerConnected(ServerEventListener)

api/src/main/java/dev/objz/commandbridge/api/message/Subscription.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,17 @@
55
* cancelled.
66
*
77
* <p>
8-
* When registering a listener via
8+
* Returned by
99
* {@link dev.objz.commandbridge.api.channel.MessageChannel#listen(dev.objz.commandbridge.api.message.MessageListener)}
10-
* or
11-
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#onServerConnected(dev.objz.commandbridge.api.message.ServerEventListener)},
12-
* a {@code Subscription} is returned. The caller is responsible for storing it
13-
* and calling
14-
* {@link #cancel()} when the listener is no longer needed, for example during
15-
* plugin shutdown.
10+
* and
11+
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#onServerConnected(dev.objz.commandbridge.api.message.ServerEventListener)}.
12+
* The caller is responsible for storing it and calling {@link #cancel()} when
13+
* the listener is no longer needed, for example during plugin shutdown.
1614
*
1715
* <p>
1816
* Calling {@link #cancel()} is idempotent: invoking it more than once has no
1917
* effect.
2018
*
21-
* <p>
22-
* To register a listener on a channel and retain the subscription:
23-
*
24-
* <pre>{@code
25-
* Subscription sub = api.channel(CommandPayload.class)
26-
* .listen((ctx, payload) -> handleCommand(ctx, payload));
27-
* }</pre>
28-
*
29-
* <p>
30-
* To cancel the listener, for example during plugin shutdown:
31-
*
32-
* <pre>{@code
33-
* sub.cancel();
34-
* }</pre>
35-
*
3619
* @see dev.objz.commandbridge.api.channel.MessageChannel#listen(dev.objz.commandbridge.api.message.MessageListener)
3720
* @see dev.objz.commandbridge.api.CommandBridgeAPI#onServerConnected(dev.objz.commandbridge.api.message.ServerEventListener)
3821
* @see dev.objz.commandbridge.api.message.MessageListener

api/src/main/java/dev/objz/commandbridge/api/platform/PlayerLocator.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,14 @@
1111
* A {@code PlayerLocator} is available only on the Velocity proxy. Obtain an
1212
* instance via
1313
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#playerLocator()}. On
14-
* backend servers,
15-
* that method returns {@code Optional.empty()}.
14+
* backend servers, that method returns {@code Optional.empty()}.
1615
*
1716
* <p>
18-
* The following example locates a player and sends a command to their current
19-
* server:
17+
* To resolve a player's current server:
2018
*
2119
* <pre>{@code
22-
* api.playerLocator().ifPresent(locator -> {
23-
* locator.locate(playerUUID).ifPresent(target -> {
24-
* api.channel(CommandPayload.class)
25-
* .to(List.of(target))
26-
* .send(new CommandPayload("home", RunAs.PLAYER, playerUUID));
27-
* });
28-
* });
20+
* locator.locate(playerUUID).ifPresent(target ->
21+
* Log.info("Player is on server: {}", target.id()));
2922
* }</pre>
3023
*
3124
* @see dev.objz.commandbridge.api.CommandBridgeAPI#playerLocator()

0 commit comments

Comments
 (0)