Fix format parsing in /me (Fixes #5654)

This commit is contained in:
Josh Roy 2024-02-09 22:27:04 -05:00
parent 51075adec6
commit 1e040fa7b5
1 changed files with 17 additions and 11 deletions

View File

@ -2,10 +2,8 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.FormatUtil;
import net.ess3.api.IUser;
import net.ess3.api.TranslatableException; import net.ess3.api.TranslatableException;
import net.essentialsx.api.v2.events.UserActionEvent; import net.essentialsx.api.v2.events.UserActionEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -45,9 +43,8 @@ public class Commandme extends EssentialsCommand {
user.setDisplayNick(); user.setDisplayNick();
long radius = ess.getSettings().getChatRadius(); long radius = ess.getSettings().getChatRadius();
final String toSend = tlLiteral("action", CommonPlaceholders.displayName((IUser) user), message);
if (radius < 1) { 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()))); ess.getServer().getPluginManager().callEvent(new UserActionEvent(user, message, Collections.unmodifiableCollection(ess.getServer().getOnlinePlayers())));
return; return;
} }
@ -55,7 +52,7 @@ public class Commandme extends EssentialsCommand {
final World world = user.getWorld(); final World world = user.getWorld();
final Location loc = user.getLocation(); final Location loc = user.getLocation();
final Set<Player> outList = new HashSet<>(); final Set<User> outList = new HashSet<>();
for (final Player player : Bukkit.getOnlinePlayers()) { for (final Player player : Bukkit.getOnlinePlayers()) {
final User onlineUser = ess.getUser(player); final User onlineUser = ess.getUser(player);
@ -74,13 +71,13 @@ public class Commandme extends EssentialsCommand {
} }
if (abort) { if (abort) {
if (onlineUser.isAuthorized("essentials.chat.spy")) { 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 { } else {
outList.add(player); outList.add(onlineUser);
} }
} else { } 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"); user.sendTl("localNoOne");
} }
for (final Player onlinePlayer : outList) { for (final User onlineUser : outList) {
onlinePlayer.sendMessage(toSend); 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<Player> 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 @Override