Skip to content

Commit f766397

Browse files
authored
Merge pull request #225 from M0diis/resolve-218
Resolve #218
2 parents e8dda63 + ba14975 commit f766397

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

plugin/src/main/java/at/helpch/chatchat/listener/ChatListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public void onChat(final AsyncPlayerChatEvent event) {
7373

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

76+
final var oldChannel = user.channel();
77+
78+
// We switch the user to the channel here so that the console can parse the correct channel prefix
79+
user.channel(channel);
80+
7681
event.setMessage(LegacyComponentSerializer.legacySection().serialize(
7782
MessageProcessor.processMessage(plugin, user, ConsoleUser.INSTANCE, message)
7883
));
@@ -97,6 +102,7 @@ public void onChat(final AsyncPlayerChatEvent event) {
97102
// Cancel the event if the message doesn't end up being sent
98103
// This only happens if the message contains illegal characters or if the ChatChatEvent is canceled.
99104
event.setCancelled(!MessageProcessor.process(plugin, user, channel, message, event.isAsynchronous()));
105+
user.channel(oldChannel);
100106
}
101107

102108
private static String cleanseMessage(@NotNull final String message) {

plugin/src/main/java/at/helpch/chatchat/util/MessageProcessor.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ private MessageProcessor() {
5959
throw new AssertionError("Util classes are not to be instantiated!");
6060
}
6161

62+
/**
63+
* Process a message for a user and send it to the recipients.
64+
* @param plugin The plugin instance.
65+
* @param user The user sending the message.
66+
* @param channel The channel the user is sending the message to.
67+
* @param message The message to send.
68+
* @param async Whether to process the message asynchronously.
69+
*
70+
* @return Whether the message was sent successfully.
71+
*/
6272
public static boolean process(
6373
@NotNull final ChatChatPlugin plugin,
6474
@NotNull final ChatUser user,

0 commit comments

Comments
 (0)