Annotation Interface MessageSubscribe
Marks a method as a cross-proxy message subscriber.
Methods annotated with @MessageSubscribe are automatically registered
when the containing class is registered with the messaging service.
Method Signature
The annotated method may accept either:
- One parameter: the message data type only (e.g.,
ScoreData data) - Two parameters: the source proxy ID as a
Stringfirst, followed by the message data type (e.g.,String sourceProxyId, GameEvent event)
The parameter order for two-parameter methods is always:
(String sourceProxyId, MessageType data)
Examples
@Plugin(id = "my-plugin", name = "My Plugin", version = "1.0.0")
public class MyPlugin {
// Single parameter: message data type only
@MessageSubscribe(channel = "scores")
public void onScoreUpdate(ScoreData data) {
logger.info("Player {} scored {}", data.playerName(), data.score());
}
// Two parameters: sourceProxyId first, then message data type
@MessageSubscribe(channel = "events")
public void onGameEvent(String sourceProxyId, GameEvent event) {
logger.info("Received event from proxy {}", sourceProxyId);
}
// Subscribe to system channel messages (type-safe enum)
@MessageSubscribe(SystemChannel.CHAT)
public void onChatMessage(ChatMessage message) {
// Handle cross-proxy chat
}
// Subscribe to heartbeats
@MessageSubscribe(SystemChannel.HEARTBEAT)
public void onHeartbeat(HeartbeatMessage message) {
logger.info("Proxy {} is alive", message.sourceProxyId());
}
}
Registration
// In your plugin's onEnable:
proxy.getMessagingService().registerListener(this);
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe channel name for plugin-specific messages.booleanWhether to receive messages sent by this proxy instance.The system channel to subscribe to.
-
Element Details
-
value
SystemChannel valueThe system channel to subscribe to.Use this for subscribing to built-in system channels like
SystemChannel.CHATorSystemChannel.HEARTBEAT.Leave as
SystemChannel.NONEwhen usingchannel()for plugin messages.- Returns:
- the system channel to subscribe to
- Default:
NONE
-
channel
String channelThe channel name for plugin-specific messages.When specified, the plugin ID is automatically inferred from the
@Pluginannotation on the listener class (or its enclosing plugin class).Leave empty when using
value()with a system channel.- Returns:
- the channel name within the plugin
- Default:
""
-
includeSelf
boolean includeSelfWhether to receive messages sent by this proxy instance.Default is
false- messages from the local proxy are filtered out.- Returns:
- true to include self-messages
- Default:
false
-