Hello! I’m working on a plugin that does things when certain messages in chat appear. For example when the server says something I relay it to discord. This all works fine. But now I want to do the same when certain messages from other plugins come in. One plugin for example is using the MessageChannel.TO_ALL.send() method to send the message.My current function looks like:
@Listener(order = Order.EARLY)
public void onChat(MessageChannelEvent event) {
String chatMessage = event.getMessage().toPlain();
logger.info(chatMessage);
if (event.getChannel().isPresent()) {
MessageChannel channel = event.getChannel().get();
logger.info(channel.getClass().getName().toString());
if (channel.getClass().getName().startsWith("org.spongepowered.api.text.channel.MessageChannel")) {
Boolean foundLiteral = checkForLiteral(chatMessage);
Boolean foundContains = checkForContains(chatMessage);
Boolean foundStartsWith = checkForStartsWith(chatMessage);
Boolean foundEndsWith = checkForEndsWith(chatMessage);
if (foundLiteral || foundContains || foundStartsWith || foundEndsWith) {
event.setMessageCancelled(true);
logger.info("Attempting to relay server message to Discord");
chatMessage.replaceAll("\\*\\*", "");
sendMessage(Text.of(TextColors.LIGHT_PURPLE, chatMessage));
sendDiscordMessage(chatMessage);
}
}
}
}
But I noticed that messages from plugins are not coming in. What is the correct way of catching those?