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
This commit is contained in:
latiku 2020-08-04 10:38:53 -04:00 committed by GitHub
parent 6995be7dbd
commit d35b4b9128
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();