Compare commits
6 Commits
b959de5052
...
8b35efb147
Author | SHA1 | Date |
---|---|---|
William B | 8b35efb147 | |
Josh Roy | 4109d17741 | |
William B | a19dd739ac | |
William Beemer | 95cd4ad376 | |
William Beemer | b92e0432c3 | |
William Beemer | 2fe84d4629 |
|
@ -57,6 +57,7 @@ public final class MessageType {
|
|||
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);
|
||||
|
@ -68,7 +69,7 @@ public final class MessageType {
|
|||
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}.
|
||||
|
|
|
@ -48,6 +48,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;
|
||||
|
@ -438,6 +439,10 @@ public class DiscordSettings implements IConf {
|
|||
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);
|
||||
|
@ -574,6 +579,8 @@ public class DiscordSettings implements IConf {
|
|||
"username", "displayname", "controllername", "controllerdisplayname", "reason");
|
||||
kickFormat = generateMessageFormat(getFormatString("kick"), "{displayname} was kicked with reason: {reason}", false,
|
||||
"username", "displayname", "reason");
|
||||
pmToDiscordFormat = generateMessageFormat(getFormatString("private-chat"), "{sender-username} -> {receiver-username}: {message}", false,
|
||||
"sender-username", "sender-displayname", "receiver-username", "receiver-displayname", "message");
|
||||
|
||||
plugin.onReload();
|
||||
}
|
||||
|
|
|
@ -139,6 +139,7 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
|||
final String strippedContent = FormatUtil.stripFormat(message);
|
||||
|
||||
final String webhookChannelId = typeToChannelId.get(event.getType());
|
||||
|
||||
if (webhookChannelId != null) {
|
||||
final WrappedWebhookClient client = channelIdToWebhook.get(webhookChannelId);
|
||||
if (client != null) {
|
||||
|
@ -153,6 +154,7 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
|||
logger.warning(tlLiteral("discordNoSendPermission", channel.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
channel.sendMessage(strippedContent)
|
||||
.setAllowedMentions(groupMentions ? null : DiscordUtil.NO_GROUP_MENTIONS)
|
||||
.queue();
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.Console;
|
|||
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;
|
||||
|
@ -16,6 +17,7 @@ import net.essentialsx.api.v2.services.discord.MessageType;
|
|||
import net.essentialsx.discord.JDADiscordService;
|
||||
import net.essentialsx.discord.util.DiscordUtil;
|
||||
import net.essentialsx.discord.util.MessageUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -47,6 +49,25 @@ public class BukkitListener implements Listener {
|
|||
|
||||
// Bukkit Events
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPrivateMessage(PrivateMessageSentEvent event) {
|
||||
final Player sender = Bukkit.getPlayer(event.getSender().getUUID());
|
||||
final Player recipient = Bukkit.getPlayer(event.getRecipient().getUUID());
|
||||
|
||||
if (sender.hasPermission("essentials.chat.spy.exempt")) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendDiscordMessage(MessageType.DefaultTypes.PRIVATE_CHAT,
|
||||
MessageUtil.formatMessage(jda.getSettings().getPmToDiscordFormat(),
|
||||
MessageUtil.sanitizeDiscordMarkdown(sender.getName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(sender.getDisplayName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(recipient.getName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(recipient.getDisplayName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getMessage())),
|
||||
sender);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onMute(MuteStatusChangeEvent event) {
|
||||
if (!event.getValue()) {
|
||||
|
|
|
@ -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
|
||||
|
@ -432,3 +434,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: "{sender-username} -> {receiver-username}: {message}"
|
||||
|
|
Loading…
Reference in New Issue