Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Essentials/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ nickname-prefix: '~'
max-nick-length: 15

# The regex pattern used to determine if a requested nickname should be allowed for use.
# If the a request nickname does not matched this pattern, the nickname will be rejected.
# If the a requested nickname does not matched this pattern, the nickname will be rejected.
# Users with essentials.nick.allowunsafe will be able to bypass this check.
allowed-nicks-regex: '^[a-zA-Z_0-9§]+$'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static final class DefaultTypes {
public final static MessageType FIRST_JOIN = new MessageType("first-join", true);
public final static MessageType LEAVE = new MessageType("leave", true);
public final static MessageType CHAT = new MessageType("chat", true);
public final static MessageType PRIVATE_CHAT = new MessageType("private-chat", true);
public final static MessageType DEATH = new MessageType("death", true);
public final static MessageType AFK = new MessageType("afk", true);
public final static MessageType ADVANCEMENT = new MessageType("advancement", true);
Expand All @@ -68,7 +69,7 @@ public static final class DefaultTypes {
public final static MessageType LOCAL = new MessageType("local", true);
public final static MessageType QUESTION = new MessageType("question", true);
public final static MessageType SHOUT = new MessageType("shout", true);
private final static MessageType[] VALUES = new MessageType[]{JOIN, FIRST_JOIN, LEAVE, CHAT, DEATH, AFK, ADVANCEMENT, ACTION, SERVER_START, SERVER_STOP, KICK, MUTE, LOCAL, QUESTION, SHOUT};
private final static MessageType[] VALUES = new MessageType[]{JOIN, FIRST_JOIN, LEAVE, CHAT, PRIVATE_CHAT, DEATH, AFK, ADVANCEMENT, ACTION, SERVER_START, SERVER_STOP, KICK, MUTE, LOCAL, QUESTION, SHOUT};

/**
* Gets an array of all the default {@link MessageType MessageTypes}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class DiscordSettings implements IConf {
private MessageFormat permMuteReasonFormat;
private MessageFormat unmuteFormat;
private MessageFormat kickFormat;
private MessageFormat pmToDiscordFormat;

public DiscordSettings(EssentialsDiscord plugin) {
this.plugin = plugin;
Expand Down Expand Up @@ -445,6 +446,10 @@ public MessageFormat getKickFormat() {
return kickFormat;
}

public MessageFormat getPmToDiscordFormat() {
return pmToDiscordFormat;
}

private String getFormatString(String node) {
final String pathPrefix = node.startsWith(".") ? "" : "messages.";
return config.getString(pathPrefix + (pathPrefix.isEmpty() ? node.substring(1) : node), null);
Expand Down Expand Up @@ -581,6 +586,8 @@ public void reloadConfig() {
"username", "displayname", "controllername", "controllerdisplayname", "reason");
kickFormat = generateMessageFormat(getFormatString("kick"), "{displayname} was kicked with reason: {reason}", false,
"username", "displayname", "reason");
pmToDiscordFormat = generateMessageFormat(getFormatString("private-chat"), "[SocialSpy] {sender-username} -> {receiver-username}: {message}", false,
"sender-username", "sender-displayname", "receiver-username", "receiver-displayname", "message");

plugin.onReload();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.VersionUtil;
import net.ess3.api.events.PrivateMessageSentEvent;
import net.ess3.api.IUser;
import net.ess3.api.events.AfkStatusChangeEvent;
import net.ess3.api.events.MuteStatusChangeEvent;
Expand Down Expand Up @@ -47,6 +48,23 @@ public void onDiscordMessage(DiscordMessageEvent event) {

// Bukkit Events

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPrivateMessage(PrivateMessageSentEvent event) {

if (event.getSender() instanceof IUser && ((IUser) event.getSender()).isAuthorized("essentials.chat.spy.exempt")) {
return;
}

sendDiscordMessage(MessageType.DefaultTypes.PRIVATE_CHAT,
MessageUtil.formatMessage(jda.getSettings().getPmToDiscordFormat(),
MessageUtil.sanitizeDiscordMarkdown(event.getSender().getName()),
MessageUtil.sanitizeDiscordMarkdown(event.getSender().getDisplayName()),
MessageUtil.sanitizeDiscordMarkdown(event.getRecipient().getName()),
MessageUtil.sanitizeDiscordMarkdown(event.getRecipient().getDisplayName()),
MessageUtil.sanitizeDiscordMarkdown(event.getMessage())),
event.getSender() instanceof IUser ? ((IUser) event.getSender()).getBase() : null);
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMute(MuteStatusChangeEvent event) {
if (!event.getValue()) {
Expand Down
10 changes: 10 additions & 0 deletions EssentialsDiscord/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ message-types:
kick: staff
# Message sent when a player's mute state is changed on the Minecraft server.
mute: staff
# Message sent when a private message (/msg, /whisper, etc.) is sent on the Minecraft Server.
private-chat: none
# Message sent when a player talks in local chat.
# use-essentials-events must be set to "true" for this to work.
local: none
Expand Down Expand Up @@ -433,3 +435,11 @@ messages:
# - {displayname}: The display name of the user who got kicked
# - {reason}: The reason the player was kicked
kick: "{displayname} was kicked with reason: {reason}"
# This is the message that is used to relay minecraft private messages in Discord.
# The following placeholders can be used here:
# - {sender-username}: The username of the player sending the message
# - {sender-displayname}: The display name of the player sending the message (This would be their nickname)
# - {receiver-username}: The username of the player receiving the message
# - {receiver-displayname}: The display name of the player receiving the message (This would be their nickname)
# - {message}: The content of the message being sent
pms-to-discord: "[SocialSpy] {sender-username} -> {receiver-username}: {message}"
Loading