mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Initial work for whisper toggling
This commit is contained in:
1 parent
1b61afb687
commit
5af70daea9
8 files changed
+154
No files matched your search
@@ -284,6 +284,22 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
*/
|
||||
void spying(boolean spying);
|
||||
|
||||
/**
|
||||
* Controls if the player should receive direct messages or if they should be hidden.
|
||||
*
|
||||
* @return if the player is ignoring direct messages
|
||||
* @since 2.1.0
|
||||
*/
|
||||
boolean ignoringDirectMessages();
|
||||
|
||||
/**
|
||||
* Sets whether the player should receive direct messages or if they should be hidden.
|
||||
*
|
||||
* @param ignoring if the player is ignoring direct messages
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void ignoringDirectMessages(final boolean ignoring);
|
||||
|
||||
/**
|
||||
* Sends the message as the player.
|
||||
*
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
+92
@@ -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) {
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ command.nickname.others.reset.description=Removes any set nickname from the targ
|
||||
command.reload.description=Reloads Carbon's config, channel settings, and translations. Will not load or unload any channels.
|
||||
command.reply.argument.message=The message to reply with.
|
||||
command.reply.description=Sends a message to the last player that messaged you.
|
||||
command.togglemsg.description=Allows and disallows other players from mesaging you.
|
||||
command.unignore.argument.player=The name of the player to unignore.
|
||||
command.unignore.argument.uuid=The UUID of the player to unignore.
|
||||
command.unignore.description=Stops hiding messages from the specified player.
|
||||
@@ -99,7 +100,10 @@ whisper.error=<red>Failed to send private message
|
||||
whisper.from=<gold>[<green><sender_display_name></green>] -> [<green>You</green>] <message>
|
||||
whisper.ignored_by_target=<red><target> <red>is ignoring you
|
||||
whisper.ignoring_target=<red>You are ignoring <target>
|
||||
whisper.ignoring_all=<red>You cannot send messages while they are ignored!
|
||||
whisper.to=<gold>[<green>You</green>] -> [<green><recipient_display_name></green>] <message>
|
||||
whisper.toggled.on=Now receiving private messages.
|
||||
whisper.toggled.off=No longer receiving private messages.
|
||||
channel.radius.empty_recipients=<red>You're not close enough to anyone to send a message
|
||||
channel.joined=<green>You have rejoined the channel</green>
|
||||
channel.left=<red>You have left the channel</red>
|
||||
|
||||
Reference in new issue
Block a user