From d35b4b9128455d1a81da9923e89905ece6ed0540 Mon Sep 17 00:00:00 2001 From: latiku Date: Tue, 4 Aug 2020 10:38:53 -0400 Subject: [PATCH] Don't send chat messages if they only contain formatting codes (#3505) Closes #3442. When a player with the appropriate permission node to use color formatting codes sends a message with nothing but valid formatting code, a message with an empty line is sent. This PR solves this issue by checking if the final formatted message is just a color code, and if so, cancels the event. Below are some attached screenshots with debug messages containing the event's raw message, the event message after it is formatted, and in the case of the "before" screenshot, the message sent in-game. Before: https://user-images.githubusercontent.com/47498808/87505823-7a8c5080-c62f-11ea-99b4-29fc6eaff042.png After: https://user-images.githubusercontent.com/47498808/87505857-8c6df380-c62f-11ea-95f8-dd59dadaf27c.png --- .../chat/EssentialsChatPlayerListenerLowest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 5963fc04f..1c62cc751 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.chat; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import net.ess3.api.IEssentials; +import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -38,6 +39,12 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer { // This listener should apply the general chat formatting only...then return control back the event handler event.setMessage(FormatUtil.formatMessage(user, "essentials.chat", event.getMessage())); + + if ((ChatColor.stripColor(event.getMessage())).length() == 0) { + event.setCancelled(true); + return; + } + String group = user.getGroup(); String world = user.getWorld().getName();