Skip to content

Commit

Permalink
Fix message display issues from Adventure refactor (#5648)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Roy <[email protected]>
  • Loading branch information
mdcfe and JRoy authored Feb 5, 2024
1 parent 16e2972 commit 0d1462a
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,8 @@ public void cleanupOpenInventories() {
@Override
public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) {
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 {
sender.sendTl("errorWithMessage", exception.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,11 +642,10 @@ public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent eve
if (!user.isAuthorized("essentials.chat.spy.exempt")) {
for (final User spyer : ess.getOnlineUsers()) {
if (spyer.isSocialSpyEnabled() && !player.equals(spyer.getBase())) {
if (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers()) {
spyer.sendMessage(spyer.playerTl("socialSpyMutedPrefix") + player.getDisplayName() + ": " + event.getMessage());
} else {
spyer.sendMessage(spyer.playerTl("socialSpyPrefix") + player.getDisplayName() + ": " + event.getMessage());
}
final Component base = (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers())
? spyer.tlComponent("socialSpyMutedPrefix")
: spyer.tlComponent("socialSpyPrefix");
spyer.sendComponent(base.append(Component.text(AdventureUtil.legacyToAdventure(player.getDisplayName()) + ": " + event.getMessage())));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ public void updateActivityOnChat(final boolean broadcast) {
}

public void checkActivity() {
// Graceful time before the first afk check call.
// Graceful time before the first afk check call.
if (System.currentTimeMillis() - lastActivity <= 10000) {
return;
}
Expand All @@ -847,7 +847,7 @@ public void checkActivity() {
lastActivity = 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()) {
if (user.isAuthorized("essentials.kick.notify")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void run(final Server server, final CommandSource sender, final String co

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

if (nomatch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void run(final Server server, final CommandSource sender, final String co
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.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerBanIpAddress", senderDisplayName, ipAddress, banReason)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.TextInput;
import com.earth2me.essentials.textreader.TextPager;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.NumberUtil;
import org.bukkit.Server;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -44,7 +45,7 @@ protected void run(final Server server, final User user, final String commandLab
final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(knownCmd.getValue().getName()) : null;
if (essCommand != null && !essCommand.getUsageStrings().isEmpty()) {
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 {
user.sendMessage(knownCmd.getValue().getUsage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void run(final Server server, final CommandSource sender, final String co
}
}

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"));

final UserKickEvent event = new UserKickEvent(user, target, kickReason);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.earth2me.essentials.commands;

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Server;
import org.bukkit.entity.Player;
Expand All @@ -14,7 +15,7 @@ public Commandkickall() {

@Override
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"));

for (final Player onlinePlayer : ess.getOnlinePlayers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.CommonPlaceholders;
import com.google.common.collect.Lists;
import net.ess3.api.IUser;
Expand Down Expand Up @@ -74,7 +75,7 @@ protected void run(final Server server, final CommandSource sender, final String
} 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public void run(final Server server, final CommandSource sender, final String co
ess.getServer().getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, new Date(banTimestamp), senderName);
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.broadcastTl((IUser) null, "essentials.ban.notify", "playerTempBanned", senderDisplayName, user.getName(), expiry, banReason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void run(final Server server, final CommandSource sender, final String co

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()) {
if (player.getAddress().getAddress().getHostAddress().equalsIgnoreCase(ipAddress)) {
player.kickPlayer(banDisplay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public void run(final Server server, final CommandSource sender, final String co
final Object[] objects;
if (timeDiff > 0) {
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));
} else {
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) {
String pluginName = "";
String pluginNameLow = "";
if (!match.equalsIgnoreCase("")) {
lines.add(user.playerTl("helpMatching", match));
lines.add(AdventureUtil.miniToLegacy(user.playerTl("helpMatching", match)));
}

final Multimap<Plugin, Command> pluginCommands = HashMultimap.create();
Expand All @@ -50,7 +50,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) {
if (pluginNameLow.equals(match)) {
lines.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);

Expand All @@ -69,7 +69,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) {
if (pluginNameLow.contains("essentials")) {
final String node = "essentials." + commandName;
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 {
if (ess.getSettings().showNonEssCommandsInHelp()) {
Expand All @@ -82,7 +82,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) {
}

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) {
boolean enabled = false;

Expand All @@ -94,11 +94,11 @@ public HelpInput(final User user, final String match, final IEssentials ess) {
}

if (enabled) {
pluginLines.add(user.playerTl("helpLine", commandName, commandDescription));
pluginLines.add(AdventureUtil.miniToLegacy(user.playerTl("helpLine", commandName, commandDescription)));
}
} else {
if (!ess.getSettings().hidePermissionlessHelp()) {
pluginLines.add(user.playerTl("helpLine", commandName, commandDescription));
pluginLines.add(AdventureUtil.miniToLegacy(user.playerTl("helpLine", commandName, commandDescription)));
}
}
}
Expand All @@ -112,7 +112,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) {
break;
}
if (match.equalsIgnoreCase("")) {
lines.add(user.playerTl("helpPlugin", pluginName, pluginNameLow));
lines.add(AdventureUtil.miniToLegacy(user.playerTl("helpPlugin", pluginName, pluginNameLow)));
}
}
} catch (final NullPointerException ignored) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.essentialsx.discordlink.listeners;

import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil;
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
import net.essentialsx.api.v2.events.UserMailEvent;
Expand Down Expand Up @@ -153,7 +154,7 @@ public void onUserLinkStatusChange(final DiscordLinkStatusChangeEvent event) {

switch (ess.getSettings().getLinkPolicy()) {
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()) {
kickTask.run();
} else {
Expand Down

0 comments on commit 0d1462a

Please sign in to comment.