From 15cac529c57914cc4621d73648768b5a4e22d1fb Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Mon, 5 Jul 2021 13:42:13 -0400 Subject: [PATCH] Improve death message validation Now takes gamerules in to account and will not send blank or null death messages. --- .../discord/listeners/BukkitListener.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/BukkitListener.java b/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/BukkitListener.java index a70182efa..8ca50902f 100644 --- a/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/BukkitListener.java +++ b/EssentialsDiscord/src/main/java/net/essentialsx/discord/listeners/BukkitListener.java @@ -3,6 +3,7 @@ package net.essentialsx.discord.listeners; 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.IUser; import net.ess3.api.events.AfkStatusChangeEvent; import net.ess3.api.events.MuteStatusChangeEvent; @@ -17,6 +18,7 @@ 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; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -148,6 +150,21 @@ public class BukkitListener implements Listener { if (isVanishHide(event.getEntity())) { return; } + + final Boolean showDeathMessages; + if (VersionUtil.getServerBukkitVersion().isHigherThan(VersionUtil.v1_12_2_R01)) { + showDeathMessages = event.getEntity().getWorld().getGameRuleValue(GameRule.SHOW_DEATH_MESSAGES); + } else { + if (!event.getEntity().getWorld().isGameRule("showDeathMessages")) { + showDeathMessages = null; + } else { + showDeathMessages = event.getEntity().getWorld().getGameRuleValue("showDeathMessages").equals("true"); + } + } + if ((showDeathMessages != null && !showDeathMessages) || event.getDeathMessage() == null || event.getDeathMessage().trim().isEmpty()) { + return; + } + sendDiscordMessage(MessageType.DefaultTypes.DEATH, MessageUtil.formatMessage(jda.getSettings().getDeathFormat(event.getEntity()), MessageUtil.sanitizeDiscordMarkdown(event.getEntity().getName()),