Skip to content

Commit

Permalink
Merge pull request #225 from M0diis/resolve-218
Browse files Browse the repository at this point in the history
Resolve #218
  • Loading branch information
BlitzOffline authored Feb 28, 2024
2 parents e8dda63 + ba14975 commit f766397
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public void onChat(final AsyncPlayerChatEvent event) {

final var consoleFormat = plugin.configManager().formats().consoleFormat();

final var oldChannel = user.channel();

// We switch the user to the channel here so that the console can parse the correct channel prefix
user.channel(channel);

event.setMessage(LegacyComponentSerializer.legacySection().serialize(
MessageProcessor.processMessage(plugin, user, ConsoleUser.INSTANCE, message)
));
Expand All @@ -97,6 +102,7 @@ public void onChat(final AsyncPlayerChatEvent event) {
// Cancel the event if the message doesn't end up being sent
// This only happens if the message contains illegal characters or if the ChatChatEvent is canceled.
event.setCancelled(!MessageProcessor.process(plugin, user, channel, message, event.isAsynchronous()));
user.channel(oldChannel);
}

private static String cleanseMessage(@NotNull final String message) {
Expand Down
10 changes: 10 additions & 0 deletions plugin/src/main/java/at/helpch/chatchat/util/MessageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ private MessageProcessor() {
throw new AssertionError("Util classes are not to be instantiated!");
}

/**
* Process a message for a user and send it to the recipients.
* @param plugin The plugin instance.
* @param user The user sending the message.
* @param channel The channel the user is sending the message to.
* @param message The message to send.
* @param async Whether to process the message asynchronously.
*
* @return Whether the message was sent successfully.
*/
public static boolean process(
@NotNull final ChatChatPlugin plugin,
@NotNull final ChatUser user,
Expand Down

0 comments on commit f766397

Please sign in to comment.