Skip to content

Commit

Permalink
feat: private messaging has now the option to configure sender and re…
Browse files Browse the repository at this point in the history
…ceiver format
  • Loading branch information
rexlManu committed Aug 10, 2023
1 parent 131d89e commit 2b3cf44
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
@Getter
public class PrivateMessagingConfig {

@Comment("The format used for private messaging.")
private String format =
@Comment("The format used for private messaging as sender.")
private String senderFormat =
"<dark_gray>[<#5E548E>PM</#5E548E>] <gray><sender_name></gray> → <#9F86C0><recipient_name></#9F86C0> »<dark_gray> <gray><message></gray>";

@Comment("The format used for private messaging as receiver.")
private String receiverFormat =
"<dark_gray>[<#5E548E>PM</#5E548E>] <gray><sender_name></gray> → <#9F86C0><recipient_name></#9F86C0> »<dark_gray> <gray><message></gray>";

@Comment("The duration (in seconds) until a recipient can no longer respond.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ public class DefaultPrivateMessagingService implements PrivateMessagingService {

@Override
public void sendMessage(User user, User recipient, String message) {
Audience.audience(this.getPlayer(user), this.getPlayer(recipient))
this.getPlayer(user)
.sendMessage(
this.miniMessage.deserialize(
configurationProvider.get().privateMessaging().format(),
configurationProvider.get().privateMessaging().senderFormat(),
Placeholder.unparsed("message", message),
Placeholder.unparsed("sender_name", user.username()),
Placeholder.unparsed("recipient_name", recipient.username())));
this.getPlayer(recipient)
.sendMessage(
this.miniMessage.deserialize(
configurationProvider.get().privateMessaging().receiverFormat(),
Placeholder.unparsed("message", message),
Placeholder.unparsed("sender_name", user.username()),
Placeholder.unparsed("recipient_name", recipient.username())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,27 @@ public void setLastRecipient(UUID senderId, UUID recipientId) {
public void sendMessage(User user, User recipient, String message) {
this.setLastRecipient(recipient.uniqueId(), user.uniqueId());

Component formattedMessage =
this.miniMessage.deserialize(
this.configurationProvider.get().privateMessaging().format(),
Placeholder.unparsed("message", message),
Placeholder.unparsed("sender_name", user.username()),
Placeholder.unparsed("recipient_name", recipient.username()));
this.getPlayer(user).ifPresent(player -> player.sendMessage(formattedMessage));
this.getPlayer(user)
.ifPresent(
player ->
player.sendMessage(
this.miniMessage.deserialize(
this.configurationProvider.get().privateMessaging().senderFormat(),
Placeholder.unparsed("message", message),
Placeholder.unparsed("sender_name", user.username()),
Placeholder.unparsed("recipient_name", recipient.username()))));

// If the recipient is on the same server, we send directly to the player.
// Otherwise, we send the message over redis to the recipient.
this.getPlayer(recipient)
.ifPresentOrElse(
player -> player.sendMessage(formattedMessage),
player ->
player.sendMessage(
this.miniMessage.deserialize(
this.configurationProvider.get().privateMessaging().receiverFormat(),
Placeholder.unparsed("message", message),
Placeholder.unparsed("sender_name", user.username()),
Placeholder.unparsed("recipient_name", recipient.username()))),
() ->
connector.publish(
Constants.PRIVATE_MESSAGING_CHANNEL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void handle(PrivateMessageData data) {
player ->
player.sendMessage(
this.miniMessage.deserialize(
this.configurationProvider.get().privateMessaging().format(),
this.configurationProvider.get().privateMessaging().receiverFormat(),
Placeholder.unparsed("message", data.message()),
Placeholder.unparsed("sender_name", sender.username()),
Placeholder.unparsed("recipient_name", recipient.username()))));
Expand Down

0 comments on commit 2b3cf44

Please sign in to comment.