mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
Add support for per-channel mutes
This commit is contained in:
1 parent
befce62375
commit
a57cd5c103
13 files changed
+137
-48
No files matched your search
@@ -31,12 +31,15 @@ public class MuteHandler {
|
||||
this.messageService = messageService;
|
||||
|
||||
carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 100, false, event -> {
|
||||
if (!event.sender().muted()) {
|
||||
return;
|
||||
for (final var muteEntry : event.sender().muteEntries()) {
|
||||
if (muteEntry.channel() != null && event.chatChannel().key().equals(muteEntry.channel())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.renderers().add(this.renderer);
|
||||
|
||||
// TODO: ShadowMuteHandler? Include that logic in here?
|
||||
event.recipients().removeIf(entry -> entry instanceof CarbonPlayer carbonPlayer &&
|
||||
!carbonPlayer.spying());
|
||||
});
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.draycia.carbon.common.users;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.punishments.MuteEntry;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
@@ -19,18 +21,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Single {
|
||||
|
||||
protected boolean deafened = false;
|
||||
protected @Nullable Component displayName = null;
|
||||
protected @Nullable UUID lastWhisperTarget = null;
|
||||
protected boolean muted = false;
|
||||
protected @Nullable ChatChannel selectedChannel = null;
|
||||
protected boolean spying = false;
|
||||
protected @Nullable Component temporaryDisplayName = null;
|
||||
protected long temporaryDisplayNameExpiration = -1;
|
||||
protected @Nullable UUID whisperReplyTarget = null;
|
||||
|
||||
// All players have these
|
||||
protected @MonotonicNonNull String username;
|
||||
protected @MonotonicNonNull UUID uuid;
|
||||
|
||||
// Display information
|
||||
protected @Nullable Component displayName = null;
|
||||
protected @Nullable Component temporaryDisplayName = null;
|
||||
protected long temporaryDisplayNameExpiration = -1;
|
||||
|
||||
// Whispers
|
||||
protected @Nullable UUID lastWhisperTarget = null;
|
||||
protected @Nullable UUID whisperReplyTarget = null;
|
||||
|
||||
// Administrative
|
||||
protected boolean spying = false;
|
||||
|
||||
// Punishments
|
||||
protected List<MuteEntry> muteEntries = new ArrayList<>();
|
||||
|
||||
public CarbonPlayerCommon(
|
||||
final String username,
|
||||
final UUID uuid
|
||||
@@ -108,13 +119,37 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean muted() {
|
||||
return this.muted;
|
||||
public List<MuteEntry> muteEntries() {
|
||||
return this.muteEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muted(final boolean muted) {
|
||||
this.muted = muted;
|
||||
public boolean muted(final ChatChannel chatChannel) {
|
||||
for (final var muteEntry : this.muteEntries) {
|
||||
if (muteEntry.channel() != null && chatChannel.key().equals(muteEntry.channel())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muted(final ChatChannel chatChannel, final boolean muted, final @Nullable UUID cause) {
|
||||
final var iterator = this.muteEntries.iterator();
|
||||
MuteEntry muteEntry;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
muteEntry = iterator.next();
|
||||
|
||||
if (muteEntry.channel() != null && chatChannel.key().equals(muteEntry.channel())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (muted) {
|
||||
this.muteEntries.add(new MuteEntry(System.currentTimeMillis(), cause, -1, chatChannel.key()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.draycia.carbon.common.users;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.punishments.MuteEntry;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -95,13 +96,18 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean muted() {
|
||||
return this.carbonPlayerCommon().muted();
|
||||
public List<MuteEntry> muteEntries() {
|
||||
return this.carbonPlayerCommon().muteEntries();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muted(boolean muted) {
|
||||
this.carbonPlayerCommon().muted(muted);
|
||||
public boolean muted(final ChatChannel chatChannel) {
|
||||
return this.carbonPlayerCommon().muted(chatChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void muted(final ChatChannel chatChannel, final boolean muted, final @Nullable UUID cause) {
|
||||
this.carbonPlayerCommon().muted(chatChannel, muted, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user