Class SubChannelHandler<S>
java.lang.Object
de.themoep.resourcepacksplugin.core.SubChannelHandler<S>
- Direct Known Subclasses:
PluginMessageListener
,PluginMessageListener
,ProxyPackListener
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Check if this listener accepts a new keyprotected String
Generate a new keyprotected abstract String
Get the type that we are sending messages toprotected boolean
handleMessage
(S source, byte[] message) Handle a message with sub channelsprotected abstract String
loadKey()
Load the key from the storageprotected ResourcePack
readPack
(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"void
reload()
Reload the handlerprotected abstract void
Save the key used for authenticating communicationprotected void
void
sendMessage
(S target, String subChannel, Consumer<com.google.common.io.ByteArrayDataOutput> out) Send a message to the target on the given sub channelprotected abstract void
sendPluginMessage
(S target, byte[] data) protected void
Set the key used for authenticating communication and save itprotected boolean
Check whether this implementation can trust the sendervoid
writePack
(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
null
is 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
-