mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-14 06:36:40 +01:00
Add fake vanish join/leave + exclude vanished messages
This commit is contained in:
parent
48532a0ae6
commit
37e3730e9d
@ -151,6 +151,14 @@ public class DiscordSettings implements IConf {
|
||||
return config.getString("avatar-url", "https://crafthead.net/helm/{uuid}");
|
||||
}
|
||||
|
||||
public boolean isVanishFakeJoinLeave() {
|
||||
return config.getBoolean("vanish-fake-join-leave", true);
|
||||
}
|
||||
|
||||
public boolean isVanishHideMessages() {
|
||||
return config.getBoolean("vanish-hide-messages", true);
|
||||
}
|
||||
|
||||
// General command settings
|
||||
|
||||
public boolean isCommandEnabled(String command) {
|
||||
|
@ -3,8 +3,10 @@ package net.essentialsx.discord.listeners;
|
||||
import com.earth2me.essentials.Console;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.api.events.MuteStatusChangeEvent;
|
||||
import net.ess3.api.events.VanishStatusChangeEvent;
|
||||
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
|
||||
import net.essentialsx.api.v2.events.discord.DiscordChatMessageEvent;
|
||||
import net.essentialsx.api.v2.events.discord.DiscordMessageEvent;
|
||||
@ -13,6 +15,7 @@ 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.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -103,36 +106,47 @@ public class BukkitListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(AsyncUserDataLoadEvent event) {
|
||||
// Delay join to let nickname load
|
||||
if (event.getJoinMessage() != null) {
|
||||
sendDiscordMessage(MessageType.DefaultTypes.JOIN,
|
||||
MessageUtil.formatMessage(jda.getSettings().getJoinFormat(event.getUser().getBase()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getUser().getName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getUser().getDisplayName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getJoinMessage())),
|
||||
false,
|
||||
jda.getSettings().isShowAvatar() ? jda.getSettings().getAvatarURL().replace("{uuid}", event.getUser().getBase().getUniqueId().toString()) : null,
|
||||
jda.getSettings().isShowName() ? event.getUser().getName() : null,
|
||||
event.getUser().getBase().getUniqueId());
|
||||
if (event.getJoinMessage() != null && !isVanishHide(event.getUser())) {
|
||||
sendJoinQuitMessage(event.getUser().getBase(), event.getJoinMessage(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
if (event.getQuitMessage() != null) {
|
||||
sendDiscordMessage(MessageType.DefaultTypes.LEAVE,
|
||||
MessageUtil.formatMessage(jda.getSettings().getQuitFormat(event.getPlayer()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getPlayer().getName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getPlayer().getDisplayName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getQuitMessage())),
|
||||
false,
|
||||
jda.getSettings().isShowAvatar() ? jda.getSettings().getAvatarURL().replace("{uuid}", event.getPlayer().getUniqueId().toString()) : null,
|
||||
jda.getSettings().isShowName() ? event.getPlayer().getName() : null,
|
||||
event.getPlayer().getUniqueId());
|
||||
if (event.getQuitMessage() != null && !isVanishHide(event.getPlayer())) {
|
||||
sendJoinQuitMessage(event.getPlayer(), event.getQuitMessage(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onVanishStatusChange(VanishStatusChangeEvent event) {
|
||||
if (!jda.getSettings().isVanishFakeJoinLeave()) {
|
||||
return;
|
||||
}
|
||||
if (event.getValue()) {
|
||||
sendJoinQuitMessage(event.getAffected().getBase(), ChatColor.YELLOW + event.getAffected().getName() + " left the game", false);
|
||||
return;
|
||||
}
|
||||
sendJoinQuitMessage(event.getAffected().getBase(), ChatColor.YELLOW + event.getAffected().getName() + " joined the game", true);
|
||||
}
|
||||
|
||||
public void sendJoinQuitMessage(final Player player, final String message, boolean join) {
|
||||
sendDiscordMessage(join ? MessageType.DefaultTypes.JOIN : MessageType.DefaultTypes.LEAVE,
|
||||
MessageUtil.formatMessage(join ? jda.getSettings().getJoinFormat(player) : jda.getSettings().getQuitFormat(player),
|
||||
MessageUtil.sanitizeDiscordMarkdown(player.getName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(player.getDisplayName()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(message),
|
||||
false,
|
||||
jda.getSettings().isShowAvatar() ? jda.getSettings().getAvatarURL().replace("{uuid}", player.getUniqueId().toString()) : null,
|
||||
jda.getSettings().isShowName() ? player.getName() : null,
|
||||
player.getUniqueId()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
if (isVanishHide(event.getEntity())) {
|
||||
return;
|
||||
}
|
||||
sendDiscordMessage(MessageType.DefaultTypes.DEATH,
|
||||
MessageUtil.formatMessage(jda.getSettings().getDeathFormat(event.getEntity()),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getEntity().getName()),
|
||||
@ -146,6 +160,10 @@ public class BukkitListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onAfk(AfkStatusChangeEvent event) {
|
||||
if (isVanishHide(event.getAffected())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final MessageFormat format;
|
||||
if (event.getValue()) {
|
||||
format = jda.getSettings().getAfkFormat(event.getAffected().getBase());
|
||||
@ -165,6 +183,9 @@ public class BukkitListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onKick(PlayerKickEvent event) {
|
||||
if (isVanishHide(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
sendDiscordMessage(MessageType.DefaultTypes.KICK,
|
||||
MessageUtil.formatMessage(jda.getSettings().getKickFormat(),
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getPlayer().getName()),
|
||||
@ -172,6 +193,14 @@ public class BukkitListener implements Listener {
|
||||
MessageUtil.sanitizeDiscordMarkdown(event.getReason())));
|
||||
}
|
||||
|
||||
private boolean isVanishHide(final Player player) {
|
||||
return isVanishHide(jda.getPlugin().getEss().getUser(player));
|
||||
}
|
||||
|
||||
private boolean isVanishHide(final IUser user) {
|
||||
return jda.getSettings().isVanishHideMessages() && user.isHidden();
|
||||
}
|
||||
|
||||
private void sendDiscordMessage(final MessageType messageType, final String message) {
|
||||
sendDiscordMessage(messageType, message, false, null, null, null);
|
||||
}
|
||||
|
@ -128,6 +128,14 @@ avatar-url: "https://crafthead.net/helm/{uuid}"
|
||||
# Whether or not player messages should show their name as the bot name in Discord.
|
||||
show-name: false
|
||||
|
||||
# Whether or not fake join and leave messages should be sent to Discord when a player toggles vanish in Minecraft.
|
||||
# Fake join/leave messages will be sent the same as real join and leave messages (and to the same channel).
|
||||
vanish-fake-join-leave: true
|
||||
|
||||
# Whether or not messages from vanished players should be sent to discord.
|
||||
# This affects join, leave, death, and afk message types by default.
|
||||
vanish-hide-messages: true
|
||||
|
||||
# Settings pertaining to the varies commands registered by EssentialsX on Discord.
|
||||
commands:
|
||||
# The execute command allows for discord users to execute MC commands from Discord.
|
||||
|
Loading…
Reference in New Issue
Block a user