From 1e040fa7b5b716b16589af61602e61471b772112 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Fri, 9 Feb 2024 22:27:04 -0500 Subject: [PATCH] Fix format parsing in /me (Fixes #5654) --- .../essentials/commands/Commandme.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandme.java index a38ae5487..46cd33d17 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandme.java @@ -2,10 +2,8 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; -import com.earth2me.essentials.utils.CommonPlaceholders; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.FormatUtil; -import net.ess3.api.IUser; import net.ess3.api.TranslatableException; import net.essentialsx.api.v2.events.UserActionEvent; import org.bukkit.Bukkit; @@ -45,9 +43,8 @@ public class Commandme extends EssentialsCommand { user.setDisplayNick(); long radius = ess.getSettings().getChatRadius(); - final String toSend = tlLiteral("action", CommonPlaceholders.displayName((IUser) user), message); if (radius < 1) { - ess.broadcastMessage(user, toSend); + ess.broadcastTl("action", user.getDisplayName(), message); ess.getServer().getPluginManager().callEvent(new UserActionEvent(user, message, Collections.unmodifiableCollection(ess.getServer().getOnlinePlayers()))); return; } @@ -55,7 +52,7 @@ public class Commandme extends EssentialsCommand { final World world = user.getWorld(); final Location loc = user.getLocation(); - final Set outList = new HashSet<>(); + final Set outList = new HashSet<>(); for (final Player player : Bukkit.getOnlinePlayers()) { final User onlineUser = ess.getUser(player); @@ -74,13 +71,13 @@ public class Commandme extends EssentialsCommand { } if (abort) { if (onlineUser.isAuthorized("essentials.chat.spy")) { - outList.add(player); // Just use the same list unless we wanted to format spyying for this. + outList.add(onlineUser); // Just use the same list unless we wanted to format spyying for this. } } else { - outList.add(player); + outList.add(onlineUser); } } else { - outList.add(player); // Add yourself to the list. + outList.add(onlineUser); // Add yourself to the list. } } @@ -88,10 +85,19 @@ public class Commandme extends EssentialsCommand { user.sendTl("localNoOne"); } - for (final Player onlinePlayer : outList) { - onlinePlayer.sendMessage(toSend); + for (final User onlineUser : outList) { + onlineUser.sendTl("action", user.getDisplayName(), message); + } + + // Only take the time to generate this list if there are listeners. + if (UserActionEvent.getHandlerList().getRegisteredListeners().length > 0) { + final Set outListPlayers = new HashSet<>(); + for (final User onlineUser : outList) { + outListPlayers.add(onlineUser.getBase()); + } + + ess.getServer().getPluginManager().callEvent(new UserActionEvent(user, message, Collections.unmodifiableCollection(outListPlayers))); } - ess.getServer().getPluginManager().callEvent(new UserActionEvent(user, message, Collections.unmodifiableCollection(outList))); } @Override