diff --git a/plugin/src/main/java/at/helpch/chatchat/listener/ChatListener.java b/plugin/src/main/java/at/helpch/chatchat/listener/ChatListener.java index 9b09664..2f72b42 100644 --- a/plugin/src/main/java/at/helpch/chatchat/listener/ChatListener.java +++ b/plugin/src/main/java/at/helpch/chatchat/listener/ChatListener.java @@ -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) )); @@ -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) { diff --git a/plugin/src/main/java/at/helpch/chatchat/util/MessageProcessor.java b/plugin/src/main/java/at/helpch/chatchat/util/MessageProcessor.java index 3aec1ee..ca8a32f 100644 --- a/plugin/src/main/java/at/helpch/chatchat/util/MessageProcessor.java +++ b/plugin/src/main/java/at/helpch/chatchat/util/MessageProcessor.java @@ -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,