Fix message display issues from Adventure refactor (#5648)

Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
MD 2024-02-05 01:31:58 +00:00 committed by GitHub
parent 16e297269d
commit 0d1462a021
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 31 additions and 26 deletions

View File

@ -904,7 +904,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
@Override @Override
public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) { public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) {
if (exception instanceof TranslatableException) { if (exception instanceof TranslatableException) {
sender.sendTl(((TranslatableException) exception).getTlKey(), ((TranslatableException) exception).getArgs()); final String tlMessage = sender.tl(((TranslatableException) exception).getTlKey(), ((TranslatableException) exception).getArgs());
sender.sendTl("errorWithMessage", AdventureUtil.parsed(tlMessage));
} else { } else {
sender.sendTl("errorWithMessage", exception.getMessage()); sender.sendTl("errorWithMessage", exception.getMessage());
} }

View File

@ -642,11 +642,10 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
if (!user.isAuthorized("essentials.chat.spy.exempt")) { if (!user.isAuthorized("essentials.chat.spy.exempt")) {
for (final User spyer : ess.getOnlineUsers()) { for (final User spyer : ess.getOnlineUsers()) {
if (spyer.isSocialSpyEnabled() && !player.equals(spyer.getBase())) { if (spyer.isSocialSpyEnabled() && !player.equals(spyer.getBase())) {
if (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers()) { final Component base = (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers())
spyer.sendMessage(spyer.playerTl("socialSpyMutedPrefix") + player.getDisplayName() + ": " + event.getMessage()); ? spyer.tlComponent("socialSpyMutedPrefix")
} else { : spyer.tlComponent("socialSpyPrefix");
spyer.sendMessage(spyer.playerTl("socialSpyPrefix") + player.getDisplayName() + ": " + event.getMessage()); spyer.sendComponent(base.append(Component.text(AdventureUtil.legacyToAdventure(player.getDisplayName()) + ": " + event.getMessage())));
}
} }
} }
} }

View File

@ -834,7 +834,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
} }
public void checkActivity() { public void checkActivity() {
// Graceful time before the first afk check call. // Graceful time before the first afk check call.
if (System.currentTimeMillis() - lastActivity <= 10000) { if (System.currentTimeMillis() - lastActivity <= 10000) {
return; return;
} }
@ -847,7 +847,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
lastActivity = 0; lastActivity = 0;
final double kickTime = autoafkkick / 60.0; final double kickTime = autoafkkick / 60.0;
this.getBase().kickPlayer(playerTl("autoAfkKickReason", kickTime)); this.getBase().kickPlayer(AdventureUtil.miniToLegacy(playerTl("autoAfkKickReason", kickTime)));
for (final User user : ess.getOnlineUsers()) { for (final User user : ess.getOnlineUsers()) {
if (user.isAuthorized("essentials.kick.notify")) { if (user.isAuthorized("essentials.kick.notify")) {

View File

@ -55,7 +55,7 @@ public class Commandban extends EssentialsCommand {
final String banDisplay = tlLiteral("banFormat", banReason, senderDisplayName); final String banDisplay = tlLiteral("banFormat", banReason, senderDisplayName);
user.getBase().kickPlayer(banDisplay); user.getBase().kickPlayer(AdventureUtil.miniToLegacy(banDisplay));
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerBanned", senderDisplayName, user.getName(), banDisplay))); ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerBanned", senderDisplayName, user.getName(), banDisplay)));
if (nomatch) { if (nomatch) {

View File

@ -52,7 +52,7 @@ public class Commandbanip extends EssentialsCommand {
banReason = tlLiteral("defaultBanReason"); banReason = tlLiteral("defaultBanReason");
} }
final String banDisplay = tlLiteral("banFormat", banReason, senderDisplayName); final String banDisplay = AdventureUtil.miniToLegacy(tlLiteral("banFormat", banReason, senderDisplayName));
ess.getServer().getBanList(BanList.Type.IP).addBan(ipAddress, banReason, null, senderName); ess.getServer().getBanList(BanList.Type.IP).addBan(ipAddress, banReason, null, senderName);
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerBanIpAddress", senderDisplayName, ipAddress, banReason))); ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerBanIpAddress", senderDisplayName, ipAddress, banReason)));

View File

@ -7,6 +7,7 @@ import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer; import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.TextInput; import com.earth2me.essentials.textreader.TextInput;
import com.earth2me.essentials.textreader.TextPager; import com.earth2me.essentials.textreader.TextPager;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.NumberUtil;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -44,7 +45,7 @@ public class Commandhelp extends EssentialsCommand {
final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(knownCmd.getValue().getName()) : null; final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(knownCmd.getValue().getName()) : null;
if (essCommand != null && !essCommand.getUsageStrings().isEmpty()) { if (essCommand != null && !essCommand.getUsageStrings().isEmpty()) {
for (Map.Entry<String, String> usage : essCommand.getUsageStrings().entrySet()) { for (Map.Entry<String, String> usage : essCommand.getUsageStrings().entrySet()) {
user.sendTl("commandHelpLineUsage", usage.getKey().replace("<command>", cmd), usage.getValue()); user.sendTl("commandHelpLineUsage", usage.getKey().replace("<command>", cmd), AdventureUtil.parsed(usage.getValue()));
} }
} else { } else {
user.sendMessage(knownCmd.getValue().getUsage()); user.sendMessage(knownCmd.getValue().getUsage());

View File

@ -39,7 +39,7 @@ public class Commandkick extends EssentialsCommand {
} }
} }
String kickReason = args.length > 1 ? getFinalArg(args, 1) : tlLiteral("kickDefault"); String kickReason = args.length > 1 ? getFinalArg(args, 1) : AdventureUtil.miniToLegacy(tlLiteral("kickDefault"));
kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n"));
final UserKickEvent event = new UserKickEvent(user, target, kickReason); final UserKickEvent event = new UserKickEvent(user, target, kickReason);

View File

@ -1,6 +1,7 @@
package com.earth2me.essentials.commands; package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -14,7 +15,7 @@ public class Commandkickall extends EssentialsCommand {
@Override @Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception { public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
String kickReason = args.length > 0 ? getFinalArg(args, 0) : tlLiteral("kickDefault"); String kickReason = args.length > 0 ? getFinalArg(args, 0) : AdventureUtil.miniToLegacy(tlLiteral("kickDefault"));
kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n")); kickReason = FormatUtil.replaceFormat(kickReason.replace("\\n", "\n").replace("|", "\n"));
for (final Player onlinePlayer : ess.getOnlinePlayers()) { for (final Player onlinePlayer : ess.getOnlinePlayers()) {

View File

@ -2,6 +2,7 @@ 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.AdventureUtil;
import com.earth2me.essentials.utils.CommonPlaceholders; import com.earth2me.essentials.utils.CommonPlaceholders;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.ess3.api.IUser; import net.ess3.api.IUser;
@ -74,7 +75,7 @@ public class Commandnear extends EssentialsCommand {
} catch (final NumberFormatException ignored) { } catch (final NumberFormatException ignored) {
} }
} }
sender.sendTl("nearbyPlayers", getLocal(sender, otherUser, radius)); sender.sendTl("nearbyPlayers", AdventureUtil.parsed(getLocal(sender, otherUser, radius)));
} }
private String getLocal(final CommandSource source, final User user, final long radius) { private String getLocal(final CommandSource source, final User user, final long radius) {

View File

@ -53,7 +53,8 @@ public class Commandtempban extends EssentialsCommand {
ess.getServer().getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, new Date(banTimestamp), senderName); ess.getServer().getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, new Date(banTimestamp), senderName);
final String expiry = DateUtil.formatDateDiff(banTimestamp); final String expiry = DateUtil.formatDateDiff(banTimestamp);
user.getBase().kickPlayer(user.playerTl("tempBanned", expiry, senderDisplayName, banReason)); final String banDisplay = user.playerTl("tempBanned", expiry, senderDisplayName, banReason);
user.getBase().kickPlayer(AdventureUtil.miniToLegacy(banDisplay));
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerTempBanned", senderDisplayName, user.getName(), expiry, banReason))); ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerTempBanned", senderDisplayName, user.getName(), expiry, banReason)));
ess.broadcastTl((IUser) null, "essentials.ban.notify", "playerTempBanned", senderDisplayName, user.getName(), expiry, banReason); ess.broadcastTl((IUser) null, "essentials.ban.notify", "playerTempBanned", senderDisplayName, user.getName(), expiry, banReason);

View File

@ -63,7 +63,7 @@ public class Commandtempbanip extends EssentialsCommand {
ess.getServer().getBanList(BanList.Type.IP).addBan(ipAddress, banReason, new Date(banTimestamp), senderName); ess.getServer().getBanList(BanList.Type.IP).addBan(ipAddress, banReason, new Date(banTimestamp), senderName);
final String banDisplay = tlLiteral("banFormat", banReason, senderDisplayName); final String banDisplay = AdventureUtil.miniToLegacy(tlLiteral("banFormat", banReason, senderDisplayName));
for (final Player player : ess.getServer().getOnlinePlayers()) { for (final Player player : ess.getServer().getOnlinePlayers()) {
if (player.getAddress().getAddress().getHostAddress().equalsIgnoreCase(ipAddress)) { if (player.getAddress().getAddress().getHostAddress().equalsIgnoreCase(ipAddress)) {
player.kickPlayer(banDisplay); player.kickPlayer(banDisplay);

View File

@ -90,11 +90,11 @@ public class Commandtogglejail extends EssentialsCommand {
final Object[] objects; final Object[] objects;
if (timeDiff > 0) { if (timeDiff > 0) {
tlKey = "jailNotifyJailedFor"; tlKey = "jailNotifyJailedFor";
objects = new Object[]{player.getName(), DateUtil.formatDateDiff(finalDisplayTime)}; objects = new Object[]{player.getName(), DateUtil.formatDateDiff(finalDisplayTime), sender.getSender().getName()};
sender.sendTl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(finalDisplayTime)); sender.sendTl("playerJailedFor", player.getName(), DateUtil.formatDateDiff(finalDisplayTime));
} else { } else {
tlKey = "jailNotifyJailed"; tlKey = "jailNotifyJailed";
objects = new Object[]{player.getName(), sender.getSender().getName()}; objects = new Object[]{player.getName(), sender.getSender().getName(), sender.getSender().getName()};
sender.sendTl("playerJailed", player.getName()); sender.sendTl("playerJailed", player.getName());
} }

View File

@ -28,7 +28,7 @@ public class HelpInput implements IText {
String pluginName = ""; String pluginName = "";
String pluginNameLow = ""; String pluginNameLow = "";
if (!match.equalsIgnoreCase("")) { if (!match.equalsIgnoreCase("")) {
lines.add(user.playerTl("helpMatching", match)); lines.add(AdventureUtil.miniToLegacy(user.playerTl("helpMatching", match)));
} }
final Multimap<Plugin, Command> pluginCommands = HashMultimap.create(); final Multimap<Plugin, Command> pluginCommands = HashMultimap.create();
@ -50,7 +50,7 @@ public class HelpInput implements IText {
if (pluginNameLow.equals(match)) { if (pluginNameLow.equals(match)) {
lines.clear(); lines.clear();
newLines.clear(); newLines.clear();
lines.add(user.playerTl("helpFrom", p.getDescription().getName())); lines.add(AdventureUtil.miniToLegacy(user.playerTl("helpFrom", p.getDescription().getName())));
} }
final boolean isOnWhitelist = user.isAuthorized("essentials.help." + pluginNameLow); final boolean isOnWhitelist = user.isAuthorized("essentials.help." + pluginNameLow);
@ -69,7 +69,7 @@ public class HelpInput implements IText {
if (pluginNameLow.contains("essentials")) { if (pluginNameLow.contains("essentials")) {
final String node = "essentials." + commandName; final String node = "essentials." + commandName;
if (!ess.getSettings().isCommandDisabled(commandName) && user.isAuthorized(node)) { if (!ess.getSettings().isCommandDisabled(commandName) && user.isAuthorized(node)) {
pluginLines.add(user.playerTl("helpLine", commandName, commandDescription)); pluginLines.add(AdventureUtil.miniToLegacy(user.playerTl("helpLine", commandName, commandDescription)));
} }
} else { } else {
if (ess.getSettings().showNonEssCommandsInHelp()) { if (ess.getSettings().showNonEssCommandsInHelp()) {
@ -82,7 +82,7 @@ public class HelpInput implements IText {
} }
if (isOnWhitelist || user.isAuthorized("essentials.help." + pluginNameLow + "." + commandName)) { if (isOnWhitelist || user.isAuthorized("essentials.help." + pluginNameLow + "." + commandName)) {
pluginLines.add(user.playerTl("helpLine", commandName, commandDescription)); pluginLines.add(AdventureUtil.miniToLegacy(user.playerTl("helpLine", commandName, commandDescription)));
} else if (permissions.length != 0) { } else if (permissions.length != 0) {
boolean enabled = false; boolean enabled = false;
@ -94,11 +94,11 @@ public class HelpInput implements IText {
} }
if (enabled) { if (enabled) {
pluginLines.add(user.playerTl("helpLine", commandName, commandDescription)); pluginLines.add(AdventureUtil.miniToLegacy(user.playerTl("helpLine", commandName, commandDescription)));
} }
} else { } else {
if (!ess.getSettings().hidePermissionlessHelp()) { if (!ess.getSettings().hidePermissionlessHelp()) {
pluginLines.add(user.playerTl("helpLine", commandName, commandDescription)); pluginLines.add(AdventureUtil.miniToLegacy(user.playerTl("helpLine", commandName, commandDescription)));
} }
} }
} }
@ -112,7 +112,7 @@ public class HelpInput implements IText {
break; break;
} }
if (match.equalsIgnoreCase("")) { if (match.equalsIgnoreCase("")) {
lines.add(user.playerTl("helpPlugin", pluginName, pluginNameLow)); lines.add(AdventureUtil.miniToLegacy(user.playerTl("helpPlugin", pluginName, pluginNameLow)));
} }
} }
} catch (final NullPointerException ignored) { } catch (final NullPointerException ignored) {

View File

@ -1,5 +1,6 @@
package net.essentialsx.discordlink.listeners; package net.essentialsx.discordlink.listeners;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil; import com.earth2me.essentials.utils.FormatUtil;
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent; import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
import net.essentialsx.api.v2.events.UserMailEvent; import net.essentialsx.api.v2.events.UserMailEvent;
@ -153,7 +154,7 @@ public class LinkBukkitListener implements Listener {
switch (ess.getSettings().getLinkPolicy()) { switch (ess.getSettings().getLinkPolicy()) {
case KICK: { case KICK: {
final Runnable kickTask = () -> event.getUser().getBase().kickPlayer(event.getUser().playerTl("discordLinkLoginKick", "/link " + finalCode, ess.getApi().getInviteUrl())); final Runnable kickTask = () -> event.getUser().getBase().kickPlayer(AdventureUtil.miniToLegacy(event.getUser().playerTl("discordLinkLoginKick", "/link " + finalCode, ess.getApi().getInviteUrl())));
if (Bukkit.isPrimaryThread()) { if (Bukkit.isPrimaryThread()) {
kickTask.run(); kickTask.run();
} else { } else {