added support for socialspy in EssentialsDiscord.
This commit is contained in:
parent
2fe84d4629
commit
b92e0432c3
|
@ -57,6 +57,7 @@ public final class MessageType {
|
||||||
public final static MessageType FIRST_JOIN = new MessageType("first-join", true);
|
public final static MessageType FIRST_JOIN = new MessageType("first-join", true);
|
||||||
public final static MessageType LEAVE = new MessageType("leave", true);
|
public final static MessageType LEAVE = new MessageType("leave", true);
|
||||||
public final static MessageType CHAT = new MessageType("chat", 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 DEATH = new MessageType("death", true);
|
||||||
public final static MessageType AFK = new MessageType("afk", true);
|
public final static MessageType AFK = new MessageType("afk", true);
|
||||||
public final static MessageType ADVANCEMENT = new MessageType("advancement", 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 LOCAL = new MessageType("local", true);
|
||||||
public final static MessageType QUESTION = new MessageType("question", true);
|
public final static MessageType QUESTION = new MessageType("question", true);
|
||||||
public final static MessageType SHOUT = new MessageType("shout", 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}.
|
* Gets an array of all the default {@link MessageType MessageTypes}.
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class DiscordSettings implements IConf {
|
||||||
private MessageFormat permMuteReasonFormat;
|
private MessageFormat permMuteReasonFormat;
|
||||||
private MessageFormat unmuteFormat;
|
private MessageFormat unmuteFormat;
|
||||||
private MessageFormat kickFormat;
|
private MessageFormat kickFormat;
|
||||||
|
private MessageFormat pmToDiscordFormat;
|
||||||
|
|
||||||
public DiscordSettings(EssentialsDiscord plugin) {
|
public DiscordSettings(EssentialsDiscord plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
@ -437,6 +438,10 @@ public class DiscordSettings implements IConf {
|
||||||
return kickFormat;
|
return kickFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageFormat getPmToDiscordFormat() {
|
||||||
|
return pmToDiscordFormat;
|
||||||
|
}
|
||||||
|
|
||||||
private String getFormatString(String node) {
|
private String getFormatString(String node) {
|
||||||
final String pathPrefix = node.startsWith(".") ? "" : "messages.";
|
final String pathPrefix = node.startsWith(".") ? "" : "messages.";
|
||||||
return config.getString(pathPrefix + (pathPrefix.isEmpty() ? node.substring(1) : node), null);
|
return config.getString(pathPrefix + (pathPrefix.isEmpty() ? node.substring(1) : node), null);
|
||||||
|
@ -573,6 +578,8 @@ public class DiscordSettings implements IConf {
|
||||||
"username", "displayname", "controllername", "controllerdisplayname", "reason");
|
"username", "displayname", "controllername", "controllerdisplayname", "reason");
|
||||||
kickFormat = generateMessageFormat(getFormatString("kick"), "{displayname} was kicked with reason: {reason}", false,
|
kickFormat = generateMessageFormat(getFormatString("kick"), "{displayname} was kicked with reason: {reason}", false,
|
||||||
"username", "displayname", "reason");
|
"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();
|
plugin.onReload();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.earth2me.essentials.Console;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
import com.earth2me.essentials.utils.FormatUtil;
|
import com.earth2me.essentials.utils.FormatUtil;
|
||||||
import com.earth2me.essentials.utils.VersionUtil;
|
import com.earth2me.essentials.utils.VersionUtil;
|
||||||
|
import net.ess3.api.events.PrivateMessageSentEvent;
|
||||||
import net.ess3.api.IUser;
|
import net.ess3.api.IUser;
|
||||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||||
import net.ess3.api.events.MuteStatusChangeEvent;
|
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.JDADiscordService;
|
||||||
import net.essentialsx.discord.util.DiscordUtil;
|
import net.essentialsx.discord.util.DiscordUtil;
|
||||||
import net.essentialsx.discord.util.MessageUtil;
|
import net.essentialsx.discord.util.MessageUtil;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -47,6 +49,25 @@ public class BukkitListener implements Listener {
|
||||||
|
|
||||||
// Bukkit Events
|
// 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)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onMute(MuteStatusChangeEvent event) {
|
public void onMute(MuteStatusChangeEvent event) {
|
||||||
if (!event.getValue()) {
|
if (!event.getValue()) {
|
||||||
|
|
|
@ -144,6 +144,8 @@ message-types:
|
||||||
kick: staff
|
kick: staff
|
||||||
# Message sent when a player's mute state is changed on the Minecraft server.
|
# Message sent when a player's mute state is changed on the Minecraft server.
|
||||||
mute: staff
|
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.
|
# Message sent when a player talks in local chat.
|
||||||
# use-essentials-events must be set to "true" for this to work.
|
# use-essentials-events must be set to "true" for this to work.
|
||||||
local: none
|
local: none
|
||||||
|
@ -432,3 +434,11 @@ messages:
|
||||||
# - {displayname}: The display name of the user who got kicked
|
# - {displayname}: The display name of the user who got kicked
|
||||||
# - {reason}: The reason the player was kicked
|
# - {reason}: The reason the player was kicked
|
||||||
kick: "{displayname} was kicked with reason: {reason}"
|
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