Redo mutehandler logic

This commit is contained in:
Draycia committed 2021-09-30 20:28:15 -07:00
1 parent e0f03795e3
commit 0505308371
2 files changed
+17 -2

No files matched your search

@@ -10,4 +10,8 @@ import java.util.UUID;
@DefaultQualifier(NonNull.class)
public record MuteEntry(long muteEpoch, @Nullable UUID muteCause, long expirationEpoch, @Nullable Key channel) {
public boolean valid() {
return System.currentTimeMillis() < expirationEpoch;
}
}
@@ -32,8 +32,19 @@ public class MuteHandler {
carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 100, false, event -> {
for (final var muteEntry : event.sender().muteEntries()) {
if (muteEntry.channel() != null && event.chatChannel().key().equals(muteEntry.channel())) {
return;
// Entry expired
if (!muteEntry.valid()) {
continue;
}
// Muted in all channels
if (muteEntry.channel() == null) {
break;
}
// Muted in the channel the message was sent in
if (event.chatChannel().key().equals(muteEntry.channel())) {
break;
}
}