Skip to content

Commit 85eee87

Browse files
author
M0diis
committed
Let MessageProcessor#process callers handle channel switching.
1 parent bcadfcd commit 85eee87

3 files changed

Lines changed: 3 additions & 14 deletions

File tree

plugin/src/main/java/at/helpch/chatchat/command/SwitchChannelCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public void switchChannel(final ChatUser user, @Join @Optional @NotNull final St
5757
return;
5858
}
5959

60-
MessageProcessor.process(plugin, user, channel, user.channel(), message, false);
60+
MessageProcessor.process(plugin, user, channel, message, false);
6161
}
6262
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,8 @@ public void onChat(final AsyncPlayerChatEvent event) {
101101

102102
// Cancel the event if the message doesn't end up being sent
103103
// This only happens if the message contains illegal characters or if the ChatChatEvent is canceled.
104-
boolean cancelled = MessageProcessor.process(plugin, user, channel, oldChannel, message, event.isAsynchronous());
105-
106-
event.setCancelled(!cancelled);
107-
108-
// If the event was cancelled, we need to reset the user back to their old channel
109-
if(cancelled) {
110-
user.channel(oldChannel);
111-
}
104+
event.setCancelled(!MessageProcessor.process(plugin, user, channel, message, event.isAsynchronous()));
105+
user.channel(oldChannel);
112106
}
113107

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

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ private MessageProcessor() {
6464
* @param plugin The plugin instance.
6565
* @param user The user sending the message.
6666
* @param channel The channel the user is sending the message to.
67-
* @param previousChannel The previous channel the user was in. Used to switch back to after sending the message.
68-
* Used to switch back when sending a message to a channel with a prefix.
6967
* @param message The message to send.
7068
* @param async Whether to process the message asynchronously.
7169
*
@@ -75,7 +73,6 @@ public static boolean process(
7573
@NotNull final ChatChatPlugin plugin,
7674
@NotNull final ChatUser user,
7775
@NotNull final Channel channel,
78-
@NotNull final Channel previousChannel,
7976
@NotNull final String message,
8077
final boolean async
8178
) {
@@ -185,7 +182,6 @@ public static boolean process(
185182
}
186183

187184
if (!userIsTarget) {
188-
user.channel(previousChannel);
189185
return true;
190186
}
191187

@@ -211,7 +207,6 @@ public static boolean process(
211207
user.playSound(mentions.sound());
212208
}
213209

214-
user.channel(previousChannel);
215210
return true;
216211
}
217212

0 commit comments

Comments
 (0)