Skip to content

Commit 798b8b5

Browse files
committed
docs(api): rewrite JavaDocs to JDK-standard quality across entire API module
1 parent 68dc517 commit 798b8b5

13 files changed

Lines changed: 650 additions & 103 deletions

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

Lines changed: 99 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,65 +13,138 @@
1313
import java.util.function.Consumer;
1414

1515
/**
16-
* Main entry point for interacting with the CommandBridge network.
16+
* Primary interface for interacting with the CommandBridge network from a third-party plugin.
1717
*
18-
* <p>Methods returning {@link java.util.Optional} indicate proxy-only features;
19-
* they return {@code Optional.empty()} on backend servers and a present value on the Velocity proxy.
18+
* <p>Use {@link #channel(Class)} to obtain typed message channels for sending and receiving
19+
* payloads. {@link #server()} and {@link #connectionState()} expose the current server's identity
20+
* and connection status. {@link #connectedServers()}, {@link #playerLocator()},
21+
* {@link #onServerConnected(ServerEventListener)}, and
22+
* {@link #onServerDisconnected(ServerEventListener)} are available only on the Velocity proxy;
23+
* they return {@code Optional.empty()} on backend servers.
24+
*
25+
* <p>Obtain an instance via {@link CommandBridgeProvider#get()}. The following example shows
26+
* common usage patterns:
27+
*
28+
* <pre>{@code
29+
* CommandBridgeAPI api = CommandBridgeProvider.get();
30+
* MessageChannel<CommandPayload> channel = api.channel(CommandPayload.class);
31+
*
32+
* // Send a command to a backend
33+
* channel.to(List.of(Platform.backend("survival-1")))
34+
* .send(new CommandPayload("say hello", RunAs.CONSOLE));
35+
*
36+
* // Broadcast to all connected servers
37+
* channel.toAll().send(new CommandPayload("say maintenance soon", RunAs.CONSOLE));
38+
*
39+
* // Subscribe to server connection events (proxy only)
40+
* api.onServerConnected(server ->
41+
* System.out.println("Connected: " + server.id())
42+
* ).ifPresent(subscriptions::add);
43+
*
44+
* // React to connection state changes (all platforms)
45+
* api.onConnectionStateChanged(state -> {
46+
* if (state.isActive()) {
47+
* // ready to send
48+
* }
49+
* });
50+
* }</pre>
51+
*
52+
* @see CommandBridgeProvider
53+
* @see dev.objz.commandbridge.api.channel.MessageChannel
2054
*/
2155
public interface CommandBridgeAPI {
2256

2357
/**
24-
* Obtains a {@link MessageChannel} for the given payload type.
58+
* Obtains a typed {@link dev.objz.commandbridge.api.channel.MessageChannel} for the given
59+
* payload type.
2560
*
26-
* @param type the payload class that identifies the channel
27-
* @param <T> the payload type
28-
* @return the message channel
61+
* @param <T> the payload type; must extend {@link dev.objz.commandbridge.api.channel.ChannelPayload}
62+
* @param type the {@link Class} token identifying the payload type; used for channel routing
63+
* @return the message channel for sending and receiving payloads of type {@code T}
64+
* @see dev.objz.commandbridge.api.channel.MessageChannel
2965
*/
3066
<T extends ChannelPayload> MessageChannel<T> channel(Class<T> type);
3167

32-
/** @return the identity of the current server */
68+
/**
69+
* Returns the identity of the server this API instance is running on.
70+
*
71+
* @return the {@link dev.objz.commandbridge.api.platform.Platform.ServerTarget} of the current
72+
* server, containing its configured identifier and platform type
73+
*/
3374
Platform.ServerTarget server();
3475

35-
/** @return the current connection state to the bridge network */
76+
/**
77+
* Returns the current connection state of this server to the CommandBridge network.
78+
*
79+
* @return the current {@link ConnectionState}
80+
* @see ConnectionState#isActive()
81+
*/
3682
ConnectionState connectionState();
3783

38-
/** @return the IDs of all currently connected servers, or empty if not available on this platform */
84+
/**
85+
* Returns the identifiers of all servers currently connected to the bridge network.
86+
*
87+
* <p>This method is available only on the Velocity proxy. On backend servers, it returns
88+
* {@code Optional.empty()}.
89+
*
90+
* @return an {@link java.util.Optional} containing a snapshot of the connected server IDs if
91+
* called on the Velocity proxy, or an empty {@code Optional} on backend servers
92+
* @see #onServerConnected(ServerEventListener)
93+
*/
3994
Optional<Set<String>> connectedServers();
4095

41-
/** @return the player location lookup service, or empty if not available on this platform */
96+
/**
97+
* Returns the player location service for resolving which server a player is connected to.
98+
*
99+
* <p>This method is available only on the Velocity proxy. On backend servers, it returns
100+
* {@code Optional.empty()}.
101+
*
102+
* @return an {@link java.util.Optional} containing the {@link PlayerLocator} if called on the
103+
* Velocity proxy, or an empty {@code Optional} on backend servers
104+
* @see dev.objz.commandbridge.api.platform.PlayerLocator#locate(java.util.UUID)
105+
*/
42106
Optional<PlayerLocator> playerLocator();
43107

44108
/**
45109
* Subscribes to server connection events.
46110
*
47-
* <p>Returns {@code Optional.empty()} on platforms where server connection events are not
48-
* available (e.g. backend servers). On the Velocity proxy, returns a present {@link Optional}
49-
* containing a {@link Subscription} that can be cancelled via {@link Subscription#cancel()}.
50-
* Use {@link java.util.Optional#ifPresent(java.util.function.Consumer)} to handle safely.
111+
* <p>This method is available only on the Velocity proxy. On backend servers, it returns
112+
* {@code Optional.empty()} and the listener is not registered.
51113
*
52-
* @param listener the listener to call when a server connects
53-
* @return a present subscription handle on the proxy, or empty on backends
114+
* @param listener the listener to invoke when a backend server connects to the bridge network;
115+
* must not be {@code null}
116+
* @return an {@link java.util.Optional} containing the {@link Subscription} on the proxy, or
117+
* an empty {@code Optional} on backends
118+
* @see #onServerDisconnected(ServerEventListener)
119+
* @see dev.objz.commandbridge.api.message.Subscription#cancel()
54120
*/
55121
Optional<Subscription> onServerConnected(ServerEventListener listener);
56122

57123
/**
58124
* Subscribes to server disconnection events.
59125
*
60-
* <p>Returns {@code Optional.empty()} on platforms where server disconnection events are not
61-
* available (e.g. backend servers). On the Velocity proxy, returns a present {@link Optional}
62-
* containing a {@link Subscription} that can be cancelled via {@link Subscription#cancel()}.
63-
* Use {@link java.util.Optional#ifPresent(java.util.function.Consumer)} to handle safely.
126+
* <p>This method is available only on the Velocity proxy. On backend servers, it returns
127+
* {@code Optional.empty()} and the listener is not registered.
64128
*
65-
* @param listener the listener to call when a server disconnects
66-
* @return a present subscription handle on the proxy, or empty on backends
129+
* @param listener the listener to invoke when a backend server disconnects from the bridge
130+
* network; must not be {@code null}
131+
* @return an {@link java.util.Optional} containing the {@link Subscription} on the proxy, or
132+
* an empty {@code Optional} on backends
133+
* @see #onServerConnected(ServerEventListener)
134+
* @see dev.objz.commandbridge.api.message.Subscription#cancel()
67135
*/
68136
Optional<Subscription> onServerDisconnected(ServerEventListener listener);
69137

70138
/**
71-
* Subscribes to connection state changes.
139+
* Subscribes to connection state changes on this server.
140+
*
141+
* <p>Available on all platforms, unlike the server event methods. The listener is invoked on
142+
* every state transition.
72143
*
73-
* @param listener the listener to call when the state changes
74-
* @return a subscription handle to cancel the listener
144+
* @param listener the consumer to call with the new {@link ConnectionState} on each transition;
145+
* must not be {@code null}
146+
* @return a {@link Subscription} that can be cancelled to stop receiving state change events
147+
* @see ConnectionState
75148
*/
76149
Subscription onConnectionStateChanged(Consumer<ConnectionState> listener);
77150
}

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

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@
22

33
import java.util.Objects;
44

5-
/** Static provider for accessing the {@link CommandBridgeAPI} instance. */
5+
/**
6+
* Static provider for obtaining the {@link CommandBridgeAPI} singleton instance.
7+
*
8+
* <p>CommandBridge registers its implementation when the plugin enables. Third-party plugins
9+
* retrieve the instance by calling {@link #get()} or {@link #get(Class)} for platform-specific
10+
* subtypes. The provider holds a single volatile reference accessible across threads.
11+
*
12+
* <p>This class cannot be instantiated. All access is through static methods.
13+
*
14+
* <pre>{@code
15+
* // Basic usage — obtain the API
16+
* CommandBridgeAPI api = CommandBridgeProvider.get();
17+
*
18+
* // Platform-specific usage (Velocity proxy only):
19+
* // VelocityCommandBridgeAPI velocityApi =
20+
* // CommandBridgeProvider.get(VelocityCommandBridgeAPI.class);
21+
* }</pre>
22+
*
23+
* @see CommandBridgeAPI
24+
*/
625
public final class CommandBridgeProvider {
726

827
private static volatile CommandBridgeAPI instance;
@@ -12,8 +31,14 @@ private CommandBridgeProvider() {
1231
}
1332

1433
/**
15-
* @return the registered API instance
16-
* @throws IllegalStateException if the API is not registered
34+
* Returns the registered {@link CommandBridgeAPI} instance.
35+
*
36+
* <p>This method is safe to call from any thread after CommandBridge has enabled.
37+
*
38+
* @return the registered {@code CommandBridgeAPI} instance; never {@code null}
39+
* @throws IllegalStateException if CommandBridge is not installed, not yet enabled,
40+
* or the API has not been registered
41+
* @see #get(Class)
1742
*/
1843
public static CommandBridgeAPI get() {
1944
if (instance == null) {
@@ -23,12 +48,18 @@ public static CommandBridgeAPI get() {
2348
}
2449

2550
/**
26-
* Obtains the API instance cast to a specific type.
51+
* Returns the registered {@link CommandBridgeAPI} instance cast to the specified subtype.
2752
*
28-
* @param type the API class type
29-
* @param <T> the API type
30-
* @return the cast API instance
31-
* @throws IllegalStateException if the instance is not available or compatible
53+
* <p>Use this method when accessing a platform-specific extension of the API. The cast is
54+
* validated at runtime; if the registered instance does not implement the requested type,
55+
* an {@link IllegalStateException} is thrown.
56+
*
57+
* @param <T> the expected API subtype; must extend {@link CommandBridgeAPI}
58+
* @param type the {@link Class} token of the expected subtype; must not be {@code null}
59+
* @return the API instance cast to {@code T}; never {@code null}
60+
* @throws IllegalStateException if the API is not registered, or if the registered instance
61+
* is not an instance of {@code type}
62+
* @see #get()
3263
*/
3364
public static <T extends CommandBridgeAPI> T get(Class<T> type) {
3465
CommandBridgeAPI api = get();
@@ -39,10 +70,14 @@ public static <T extends CommandBridgeAPI> T get(Class<T> type) {
3970
}
4071

4172
/**
42-
* Registers the API implementation.
73+
* Registers the {@link CommandBridgeAPI} implementation.
74+
*
75+
* <p>This method is called internally by the CommandBridge plugin during startup and is not
76+
* intended for use by third-party plugins.
4377
*
44-
* @param impl the implementation to register
78+
* @param impl the implementation to register; must not be {@code null}
4579
* @throws IllegalStateException if an implementation is already registered
80+
* @throws NullPointerException if {@code impl} is {@code null}
4681
*/
4782
public static synchronized void register(CommandBridgeAPI impl) {
4883
Objects.requireNonNull(impl);
@@ -52,7 +87,13 @@ public static synchronized void register(CommandBridgeAPI impl) {
5287
instance = impl;
5388
}
5489

55-
/** Unregisters the current API implementation. */
90+
/**
91+
* Clears the registered {@link CommandBridgeAPI} implementation.
92+
*
93+
* <p>Called internally by the CommandBridge plugin during shutdown. After this method returns,
94+
* calls to {@link #get()} will throw {@link IllegalStateException} until a new implementation
95+
* is registered.
96+
*/
5697
public static synchronized void unregister() {
5798
instance = null;
5899
}
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
package dev.objz.commandbridge.api.channel;
22

3-
/** Marker interface for data sent over a {@link MessageChannel}. */
3+
/**
4+
* Marker interface for all data types that can be sent over a
5+
* {@link dev.objz.commandbridge.api.channel.MessageChannel}.
6+
*
7+
* <p>Implementing this interface registers a type as a valid payload. The
8+
* {@link dev.objz.commandbridge.api.channel.MessageChannel} uses the payload's {@code Class}
9+
* token for channel routing and type-safe dispatch.
10+
*
11+
* <p>{@link dev.objz.commandbridge.api.channel.command.CommandPayload} is the built-in
12+
* implementation for command execution. Custom payload types can be created by implementing
13+
* this interface and using them with
14+
* {@link dev.objz.commandbridge.api.CommandBridgeAPI#channel(Class)}.
15+
*
16+
* <p>Example of a custom payload type:
17+
* <pre>{@code
18+
* public record MyPayload(String data) implements ChannelPayload {}
19+
*
20+
* MessageChannel<MyPayload> channel = api.channel(MyPayload.class);
21+
* channel.toAll().send(new MyPayload("hello"));
22+
* }</pre>
23+
*
24+
* @see dev.objz.commandbridge.api.channel.command.CommandPayload
25+
* @see dev.objz.commandbridge.api.channel.MessageChannel
26+
*/
427
public interface ChannelPayload {
528
}

0 commit comments

Comments
 (0)