Class SubChannelHandler<S>
java.lang.Object
de.themoep.resourcepacksplugin.core.SubChannelHandler<S>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanCheck if this listener accepts a new keyprotected StringGenerate a new keyprotected abstract StringGet the type that we are sending messages toprotected booleanhandleMessage(S source, byte[] message) Handle a message with sub channelsprotected abstract StringloadKey()Load the key from the storageprotected ResourcePackreadPack(com.google.common.io.ByteArrayDataInput in) Read a pack from the inputBiConsumer<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"voidreload()Reload the handlerprotected abstract voidSave the key used for authenticating communicationprotected voidvoidsendMessage(S target, String subChannel, Consumer<com.google.common.io.ByteArrayDataOutput> out) Send a message to the target on the given sub channelprotected abstract voidsendPluginMessage(S target, byte[] data) protected voidSet the key used for authenticating communication and save itprotected booleanCheck whether this implementation can trust the sendervoidwritePack(com.google.common.io.ByteArrayDataOutput out, ResourcePack pack) Write a pack to the output.
-
Field Details
-
MESSAGING_CHANNEL
- See Also:
-
-
Constructor Details
-
SubChannelHandler
-
-
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 sensitivereaction- The reaction that should happen- Returns:
- The previously registered Reaction or null
-
handleMessage
Handle a message with sub channels- Parameters:
source- The source of the plugin messagemessage- The message that was received- Returns:
- Whether the message was handled or not
-
sendKey
-
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 tosubChannel- The sub channel to send the message onout- The output to write to
-
writePack
Write a pack to the output. If the pack is null, an empty string will be written- Parameters:
out- The output to write topack- The pack to write
-
readPack
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
nullis returned
-
sendPluginMessage
-
reload
public void reload()Reload the handler -
generateKey
Generate a new key -
setKey
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
Save the key used for authenticating communication- Parameters:
key- The key to set
-
loadKey
Load the key from the storage- Returns:
- The key (or null if none is stored)
-
getTargetType
Get the type that we are sending messages to- Returns:
- The type
-