Package wtf.choco.veinminer.network
Class PluginMessageRegistry<T extends PluginMessageListener>
java.lang.Object
wtf.choco.veinminer.network.PluginMessageRegistry<T>
- Type Parameters:
T
- the type of plugin message listener for messages in this registry
Represents an internal registry mapping plugin messages to ids and constructors.
-
Method Summary
Modifier and TypeMethodDescription@Nullable PluginMessage<T>
createPluginMessage
(int messageId, @NotNull PluginMessageByteBuffer buffer) Create aPluginMessage
with the given message id and the providedPluginMessageByteBuffer
data.int
getPluginMessageId
(@NotNull Class<?> message) Get the id of the given plugin message class.int
Get the amount of messages registered to this message registry.@NotNull Map<Class<? extends PluginMessage<T>>,
Integer> Get aMap
containing all registered messages to their internal protocol ids.<M extends PluginMessage<T>>
@NotNull PluginMessageRegistry<T>registerMessage
(@NotNull Class<M> messageClass, @NotNull Function<PluginMessageByteBuffer, M> messageConstructor) Register a newPluginMessage
to this protocol.
-
Method Details
-
registerMessage
@NotNull public <M extends PluginMessage<T>> @NotNull PluginMessageRegistry<T> registerMessage(@NotNull @NotNull Class<M> messageClass, @NotNull @NotNull Function<PluginMessageByteBuffer, M> messageConstructor) Register a newPluginMessage
to this protocol.- Type Parameters:
M
- the message- Parameters:
messageClass
- the message classmessageConstructor
- a supplier to construct the message- Returns:
- this instance. Allows for chained message calls
-
getRegisteredMessageAmount
public int getRegisteredMessageAmount()Get the amount of messages registered to this message registry.- Returns:
- the amount of messages
-
getPluginMessageId
Get the id of the given plugin message class.- Parameters:
message
- the class of the message whose id to get- Returns:
- the id of the plugin message, or -1 if no message exists
-
createPluginMessage
@Nullable public @Nullable PluginMessage<T> createPluginMessage(int messageId, @NotNull @NotNull PluginMessageByteBuffer buffer) Create aPluginMessage
with the given message id and the providedPluginMessageByteBuffer
data.- Parameters:
messageId
- the id of the message to createbuffer
- the buffer containing message data- Returns:
- the created message
-
getRegisteredMessages
@NotNull @VisibleForTesting public @NotNull Map<Class<? extends PluginMessage<T>>,Integer> getRegisteredMessages()Get aMap
containing all registered messages to their internal protocol ids.- Returns:
- all registered messages
- API Note:
- THIS IS NOT API AND IS ONLY VISIBLE FOR DOCUMENTATION PURPOSES
-