Skip to content

Commit 6d4157e

Browse files
authored
Merge branch 'main' into fix-console-reply
2 parents 3df6422 + 75ff47b commit 6d4157e

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

src/main/java/pro/cloudnode/smp/cloudnodemsg/Permission.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ public final class Permission {
4242
* Allows to send private message even when the target have their private messages toggled
4343
*/
4444
public final static @NotNull String TOGGLE_BYPASS = "cloudnodemsg.toggle.bypass";
45+
46+
/**
47+
* Allows to see the private messages of other players
48+
*/
49+
public final static @NotNull String SPY = "cloudnodemsg.spy";
4550
}

src/main/java/pro/cloudnode/smp/cloudnodemsg/PluginConfig.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ public PluginConfig(final @NotNull FileConfiguration config) {
5757
);
5858
}
5959

60+
/**
61+
* Private message format as seen by people with the spy permission and console
62+
* <p>Placeholders:</p>
63+
* <ul>
64+
* <li>{@code <sender>} - the username of the message sender</li>
65+
* <li>{@code <recipient>} - the username of the message recipient</li>
66+
* <li>{@code <message>} - the message text</li>
67+
* </ul>
68+
*
69+
* @param sender The username of the message sender
70+
* @param recipient The username of the message recipient
71+
* @param message The message text
72+
*/
73+
public @NotNull Component spy(final @NotNull String sender, final @NotNull String recipient, final @NotNull Component message) {
74+
return MiniMessage.miniMessage().deserialize(Objects.requireNonNull(config.getString("spy"))
75+
.replace("<sender>", sender)
76+
.replace("<recipient>", recipient),
77+
Placeholder.component("message", message)
78+
);
79+
}
80+
6081
/**
6182
* Player has successfully been ignored
6283
* <p>Placeholders:</p>

src/main/java/pro/cloudnode/smp/cloudnodemsg/message/Message.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public void send() throws InvalidPlayerError {
5454
if (senderPlayer.isPresent() && !Message.hasChannel(senderPlayer.get(), recipient))
5555
setReplyTo(sender, recipient);
5656

57+
sendSpyMessage(sender, recipient, message);
58+
5759
if (
5860
(recipientPlayer.isPresent() && Message.isIgnored(recipientPlayer.get(), sender))
5961
&&
@@ -78,6 +80,24 @@ public static void sendMessage(final @NotNull OfflinePlayer recipient, final @No
7880
else if (recipient.isOnline()) Objects.requireNonNull(recipient.getPlayer()).sendMessage(message);
7981
}
8082

83+
/**
84+
* Send social spy to online players with permission
85+
*/
86+
public static void sendSpyMessage(final @NotNull OfflinePlayer sender, final @NotNull OfflinePlayer recipient, final @NotNull Component message) {
87+
final @NotNull String senderName = sender.getUniqueId().equals(console.getUniqueId()) ? CloudnodeMSG.getInstance().config().consoleName() : Optional.ofNullable(sender.getName()).orElse("Unknown Player");
88+
final @NotNull String recipientName = recipient.getUniqueId().equals(console.getUniqueId()) ? CloudnodeMSG.getInstance().config().consoleName() : Optional.ofNullable(recipient.getName()).orElse("Unknown Player");
89+
for (final @NotNull Player player : CloudnodeMSG.getInstance().getServer().getOnlinePlayers()) {
90+
if (
91+
!player.hasPermission(Permission.SPY)
92+
|| player.getUniqueId().equals(sender.getUniqueId())
93+
|| player.getUniqueId().equals(recipient.getUniqueId())
94+
) continue;
95+
sendMessage(player, CloudnodeMSG.getInstance().config().spy(senderName, recipientName, message));
96+
}
97+
if (!sender.getUniqueId().equals(console.getUniqueId()) && !recipient.getUniqueId().equals(console.getUniqueId()))
98+
sendMessage(console, CloudnodeMSG.getInstance().config().spy(senderName, recipientName, message));
99+
}
100+
81101
private static @Nullable UUID consoleReply;
82102

83103
public static final @NotNull NamespacedKey REPLY_TO = new NamespacedKey(CloudnodeMSG.getInstance(), "reply");

src/main/resources/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ incoming: '<click:suggest_command:/msg <sender> ><dark_gray>[<#60a5fa><sender></
99
# Same placeholders as incoming
1010
outgoing: '<click:suggest_command:/msg <recipient> ><dark_gray>[<#93c5fd>me</#93c5fd> <white>-></white> <#60a5fa><recipient></#60a5fa>]</dark_gray></click> <reset><#dbeafe><message></#dbeafe>'
1111

12+
# Private message format as seen by people with the spy permission and console
13+
# Same placeholders as incoming
14+
spy: '<dark_gray>[SPY] [<click:suggest_command:/msg <sender> ><gray><sender></gray></click> -> <click:suggest_command:/msg <recipient> ><gray><recipient></gray></click>] <gray><message></gray></dark_gray>'
15+
1216
# Player has successfully been ignored
1317
# Placeholders:
1418
# <player> - the player's username

0 commit comments

Comments
 (0)