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

public final class PluginMessageRegistry<T extends PluginMessageListener> extends Object
Represents an internal registry mapping plugin messages to ids and constructors.
  • 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 new PluginMessage to this protocol.
      Type Parameters:
      M - the message
      Parameters:
      messageClass - the message class
      messageConstructor - 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

      public int getPluginMessageId(@NotNull @NotNull Class<?> message)
      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 a PluginMessage with the given message id and the provided PluginMessageByteBuffer data.
      Parameters:
      messageId - the id of the message to create
      buffer - the buffer containing message data
      Returns:
      the created message
    • getRegisteredMessages

      @NotNull @VisibleForTesting public @NotNull Map<Class<? extends PluginMessage<T>>,Integer> getRegisteredMessages()
      Get a Map 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