From 9571bbb2cff964eead74358ecbf0f7e4ac10ab98 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:26:49 -0700 Subject: [PATCH] Add `sender_username` and `recipient_username` placeholders to whisper formats (closes #312) --- .../command/commands/WhisperCommand.java | 24 ++++++++------- .../common/messages/CarbonMessages.java | 30 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java index 98206dea..e0075eb6 100644 --- a/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/WhisperCommand.java @@ -171,9 +171,10 @@ public final class WhisperCommand extends CarbonCommand { return; } + final String recipientUsername = recipient.username(); if (!this.network.online(recipient) || !sender.awareOf(recipient) && !sender.hasPermission("carbon.whisper.vanished")) { final var exception = new CarbonPlayerArgument.ParseException( - recipientInputString == null ? recipient.username() : recipientInputString, + recipientInputString == null ? recipientUsername : recipientInputString, this.messages ); this.messages.errorCommandArgumentParsing(sender, CloudUtils.message(exception)); @@ -197,8 +198,8 @@ public final class WhisperCommand extends CarbonCommand { return; } - final Component senderName = sender.displayName(); - final Component recipientName = recipient.displayName(); + final Component senderDisplayName = sender.displayName(); + final Component recipientDisplayName = recipient.displayName(); final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEventImpl(sender, recipient, Component.text(message)); this.events.emit(privateChatEvent); @@ -208,11 +209,12 @@ public final class WhisperCommand extends CarbonCommand { return; } - this.messages.whisperSender(SourcedAudience.of(sender, sender), senderName, recipientName, privateChatEvent.message()); + final String senderUsername = sender.username(); + this.messages.whisperSender(SourcedAudience.of(sender, sender), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); if (localRecipient) { - this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderName, recipientName, privateChatEvent.message()); + this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); } - this.messages.whisperConsoleLog(this.server.console(), senderName, recipientName, privateChatEvent.message()); + this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound(); if (localRecipient && messageSound != null) { @@ -237,12 +239,14 @@ public final class WhisperCommand extends CarbonCommand { return; } this.userManager.user(packet.from()).thenAccept(sender -> { - final Component senderName = sender.displayName(); - final Component recipientName = recipient.displayName(); + final String senderUsername = sender.username(); + final Component senderDisplayName = sender.displayName(); + final String recipientUsername = recipient.username(); + final Component recipientDisplayName = recipient.displayName(); recipient.whisperReplyTarget(sender.uuid()); - this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderName, recipientName, packet.message()); - this.messages.whisperConsoleLog(this.server.console(), senderName, recipientName, packet.message()); + this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message()); + this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message()); final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound(); if (messageSound != null) { recipient.playSound(messageSound); diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java index 35b05957..186ede19 100644 --- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java +++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java @@ -109,26 +109,32 @@ public interface CarbonMessages { @Message("whisper.to") void whisperSender( - final SourcedAudience audience, - @Placeholder("sender_display_name") final Component senderDisplayName, - @Placeholder("recipient_display_name") final Component recipientDisplayName, - final Component message + SourcedAudience audience, + String senderUsername, + Component senderDisplayName, + String recipientUsername, + Component recipientDisplayName, + Component message ); @Message("whisper.from") void whisperRecipient( - final SourcedAudience audience, - @Placeholder("sender_display_name") final Component senderDisplayName, - @Placeholder("recipient_display_name") final Component recipientDisplayName, - final Component message + SourcedAudience audience, + String senderUsername, + Component senderDisplayName, + String recipientUsername, + Component recipientDisplayName, + Component message ); @Message("whisper.console") void whisperConsoleLog( - final Audience audience, - @Placeholder("sender_display_name") final Component senderDisplayName, - @Placeholder("recipient_display_name") final Component recipientDisplayName, - final Component message + Audience audience, + String senderUsername, + Component senderDisplayName, + String recipientUsername, + Component recipientDisplayName, + Component message ); @Message("whisper.error")