Initial work for whisper toggling

This commit is contained in:
Draycia committed 2023-08-25 00:40:21 -07:00
1 parent 1b61afb687
commit 5af70daea9
8 files changed
+154

No files matched your search

@@ -85,6 +85,11 @@ public final class ContinueCommand extends CarbonCommand {
return;
}
if (sender.ignoringDirectMessages()) {
this.carbonMessages.whisperIgnoringAll(sender);
return;
}
final String message = ctx.get("message");
final @Nullable UUID whisperTarget = sender.lastWhisperTarget();
@@ -85,6 +85,11 @@ public final class ReplyCommand extends CarbonCommand {
return;
}
if (sender.ignoringDirectMessages()) {
this.carbonMessages.whisperIgnoringAll(sender);
return;
}
final String message = ctx.get("message");
final @Nullable UUID replyTarget = sender.whisperReplyTarget();
@@ -0,0 +1,92 @@
package net.draycia.carbon.common.command.commands;
import cloud.commandframework.CommandManager;
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
import com.google.inject.Inject;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.command.ArgumentFactory;
import net.draycia.carbon.common.command.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.kyori.adventure.key.Key;
public class ToggleMessagesCommand extends CarbonCommand {
private final CommandManager<Commander> commandManager;
private final CarbonMessages carbonMessages;
private final ArgumentFactory argumentFactory;
@Inject
public ToggleMessagesCommand(
final CommandManager<Commander> commandManager,
final CarbonMessages carbonMessages,
final ArgumentFactory argumentFactory
) {
this.commandManager = commandManager;
this.carbonMessages = carbonMessages;
this.argumentFactory = argumentFactory;
}
@Override
protected CommandSettings _commandSettings() {
return new CommandSettings("togglemsg", "togglepm");
}
@Override
public Key key() {
return Key.key("carbon", "togglemsg");
}
@Override
public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.permission("carbon.togglemsg")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandToggleMsgDescription())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final boolean nowIgnoring = !sender.ignoringDirectMessages();
sender.ignoringDirectMessages(nowIgnoring);
if (nowIgnoring) {
this.carbonMessages.whispersToggledOff(sender);
} else {
this.carbonMessages.whispersToggledOn(sender);
}
})
.build();
this.commandManager.command(command);
final var toggleOn = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.permission("carbon.togglemsg")
.literal("on", "allow")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandToggleMsgDescription())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
sender.ignoringDirectMessages(false);
this.carbonMessages.whispersToggledOn(sender);
})
.build();
this.commandManager.command(toggleOn);
final var toggleOff = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.permission("carbon.togglemsg")
.literal("off", "ignore")
.senderType(PlayerCommander.class)
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandToggleMsgDescription())
.handler(handler -> {
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
sender.ignoringDirectMessages(true);
this.carbonMessages.whispersToggledOff(sender);
})
.build();
this.commandManager.command(toggleOff);
}
}
@@ -102,6 +102,11 @@ public final class WhisperCommand extends CarbonCommand {
return;
}
if (sender.ignoringDirectMessages()) {
this.carbonMessages.whisperIgnoringAll(sender);
return;
}
final String message = ctx.get("message");
final CarbonPlayer recipient = ctx.get("player");
@@ -187,6 +192,10 @@ public final class WhisperCommand extends CarbonCommand {
return;
}
if (recipient.ignoringDirectMessages() && !sender.hasPermission("carbon.togglemsg.exempt")) {
return;
}
final Component senderName = sender.displayName();
final Component recipientName = recipient.displayName();
@@ -150,12 +150,21 @@ public interface CarbonMessages {
@Placeholder("sender_display_name") final Component senderDisplayName
);
@Message("whisper.ignoring_all")
void whisperIgnoringAll(final Audience audience);
@Message("whisper.ignoring_target")
void whisperIgnoringTarget(final Audience audience, final Component target);
@Message("whisper.ignored_by_target")
void whisperTargetIgnoring(final Audience audience, final Component target);
@Message("whisper.toggled.on")
void whispersToggledOn(final Audience audience);
@Message("whisper.toggled.off")
void whispersToggledOff(final Audience audience);
/*
* =============================================================
* ========================= Nicknames =========================
@@ -343,6 +352,9 @@ public interface CarbonMessages {
@Message("command.reply.description")
Component commandReplyDescription();
@Message("command.togglemsg.description")
Component commandToggleMsgDescription();
@Message("command.unignore.argument.player")
Component commandUnignoreArgumentPlayer();
@@ -70,6 +70,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
// Whispers
protected transient @Nullable UUID lastWhisperTarget = null;
protected transient @Nullable UUID whisperReplyTarget = null;
protected boolean ignoringdirectMessages = false;
// Administrative
protected final PersistentUserProperty<Boolean> spying;
@@ -262,6 +263,16 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
this.spying.set(spying);
}
@Override
public boolean ignoringDirectMessages() {
return this.ignoringdirectMessages;
}
@Override
public void ignoringDirectMessages(final boolean ignoring) {
this.ignoringdirectMessages = ignoring;
}
@Override
public void sendMessageAsPlayer(final String message) {