Class SubChannelHandler<S>

java.lang.Object
de.themoep.resourcepacksplugin.core.SubChannelHandler<S>
Direct Known Subclasses:
PluginMessageListener, PluginMessageListener, ProxyPackListener

public abstract class SubChannelHandler<S> extends Object
  • Field Details

  • Constructor Details

  • Method Details

    • registerSubChannel

      public BiConsumer<S,com.google.common.io.ByteArrayDataInput> registerSubChannel(String name, BiConsumer<S,com.google.common.io.ByteArrayDataInput> reaction)
      Register a new sub channel with this listener on the channel "rp:plugin"
      Parameters:
      name - The name of the sub channel, case sensitive
      reaction - The reaction that should happen
      Returns:
      The previously registered Reaction or null
    • handleMessage

      protected boolean handleMessage(S source, byte[] message)
      Handle a message with sub channels
      Parameters:
      source - The source of the plugin message
      message - The message that was received
      Returns:
      Whether the message was handled or not
    • sendKey

      protected void sendKey(S target)
    • sendMessage

      public void sendMessage(S target, String subChannel, Consumer<com.google.common.io.ByteArrayDataOutput> out)
      Send a message to the target on the given sub channel
      Parameters:
      target - The target to send the message to
      subChannel - The sub channel to send the message on
      out - The output to write to
    • writePack

      public void writePack(com.google.common.io.ByteArrayDataOutput out, ResourcePack pack)
      Write a pack to the output. If the pack is null, an empty string will be written
      Parameters:
      out - The output to write to
      pack - The pack to write
    • readPack

      protected ResourcePack readPack(com.google.common.io.ByteArrayDataInput in)
      Read a pack from the input
      Parameters:
      in - The input to read from
      Returns:
      The pack that was read, if the name is empty then the empty pack will be returned, if the pack is unknown then null is returned
    • sendPluginMessage

      protected abstract void sendPluginMessage(S target, byte[] data)
    • reload

      public void reload()
      Reload the handler
    • generateKey

      protected String generateKey()
      Generate a new key
    • setKey

      protected void setKey(String key)
      Set the key used for authenticating communication and save it
      Parameters:
      key - The key to set
    • acceptsNewKey

      protected boolean acceptsNewKey()
      Check if this listener accepts a new key
      Returns:
      Whether it accepts a new key or not
    • trustsSender

      protected boolean trustsSender()
      Check whether this implementation can trust the sender
      Returns:
      Whether the sender can be trusted or not
    • saveKey

      protected abstract void saveKey(String key)
      Save the key used for authenticating communication
      Parameters:
      key - The key to set
    • loadKey

      protected abstract String loadKey()
      Load the key from the storage
      Returns:
      The key (or null if none is stored)
    • getTargetType

      protected abstract String getTargetType()
      Get the type that we are sending messages to
      Returns:
      The type