Class Channels
java.lang.Object
me.internalizable.numdrassl.api.messaging.channel.Channels
Registry of message channels with predefined system channels and custom channel support.
This class provides:
- Predefined system channels (HEARTBEAT, CHAT, etc.)
- Dynamic channel registration for plugins
- Channel lookup by ID
Predefined Channels
Channels.HEARTBEAT // numdrassl:heartbeat - Proxy health monitoring
Channels.PLAYER_COUNT // numdrassl:player-count - Player count updates
Channels.CHAT // numdrassl:chat - Cross-proxy chat
Channels.TRANSFER // numdrassl:transfer - Player transfers
Channels.PLUGIN // numdrassl:plugin - Generic plugin messages
Channels.BROADCAST // numdrassl:broadcast - Cluster-wide announcements
Custom Channels
// Register a custom channel for your plugin
MessageChannel myChannel = Channels.register("myplugin", "game-events");
// Use it for messaging
messaging.publish(myChannel, new PluginMessage(...));
messaging.subscribe(myChannel, handler);
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MessageChannelBroadcast messages to all proxies.static final MessageChannelCross-proxy chat messages.static final MessageChannelProxy heartbeat and registration.static final MessageChannelPlayer count updates.static final MessageChannelPlugin-defined custom messages (generic).static final MessageChannelPlayer transfer coordination. -
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<MessageChannel> all()Get all registered channels.static MessageChannelGet a channel by its ID.static MessageChannelgetOrRegister(String channelId) Get a channel by its ID, registering it if not found.static booleanisRegistered(String channelId) Check if a channel is registered.static MessageChannelRegister a custom channel using full ID format.static MessageChannelRegister a custom message channel.static booleanunregister(String channelId) Unregister a custom channel.
-
Field Details
-
HEARTBEAT
Proxy heartbeat and registration. Used for proxy discovery and health monitoring. -
PLAYER_COUNT
Player count updates. Proxies publish their current player count periodically. -
CHAT
Cross-proxy chat messages. Used to send messages to players connected to other proxies. -
TRANSFER
Player transfer coordination. Used when transferring players between proxies. -
PLUGIN
Plugin-defined custom messages (generic). Plugins can use this channel for simple cross-proxy communication. -
BROADCAST
Broadcast messages to all proxies. Used for cluster-wide announcements.
-
-
Method Details
-
register
Register a custom message channel.The channel ID will be
namespace:name. If a channel with this ID already exists, the existing channel is returned.- Parameters:
namespace- the namespace (typically your plugin ID)name- the channel name within the namespace- Returns:
- the registered channel
- Throws:
IllegalArgumentException- if namespace or name is invalid
-
register
Register a custom channel using full ID format.- Parameters:
channelId- the full channel ID (format: namespace:name)- Returns:
- the registered channel
- Throws:
IllegalArgumentException- if the ID format is invalid
-
get
Get a channel by its ID.- Parameters:
channelId- the channel ID- Returns:
- the channel, or null if not registered
-
getOrRegister
Get a channel by its ID, registering it if not found.- Parameters:
channelId- the channel ID (format: namespace:name)- Returns:
- the channel (existing or newly registered)
-
isRegistered
Check if a channel is registered.- Parameters:
channelId- the channel ID- Returns:
- true if registered
-
all
Get all registered channels.- Returns:
- unmodifiable collection of all channels
-
unregister
Unregister a custom channel.System channels (numdrassl:*) cannot be unregistered.
- Parameters:
channelId- the channel ID to unregister- Returns:
- true if the channel was unregistered
-