Skip to content

Commit

Permalink
Fix several regressions from adventure PR (#5637)
Browse files Browse the repository at this point in the history
* Fixes /list
* Fixes /baltop
* Fixes Social Spy
* Fixes Essentials Signs
  • Loading branch information
JRoy authored Feb 4, 2024
1 parent 3b61b3e commit 16e2972
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.NumberUtil;
import net.ess3.api.TranslatableException;
import org.bukkit.ChatColor;
import org.bukkit.Server;

import java.util.ArrayList;
Expand Down Expand Up @@ -39,13 +39,13 @@ public static String listUsers(final IEssentials ess, final List<User> users, fi
groupString.append(tlLiteral("listHiddenTag"));
}
user.setDisplayNick();
groupString.append(user.getDisplayName());
groupString.append(AdventureUtil.legacyToMini(user.getDisplayName()));

final String strippedNick = FormatUtil.stripFormat(user.getNickname());
if (ess.getSettings().realNamesOnList() && strippedNick != null && !strippedNick.equals(user.getName())) {
groupString.append(" ").append(tlLiteral("listRealName",user.getName()));
}
groupString.append(ChatColor.WHITE);
groupString.append("<white>");
}
return groupString.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ public void run() {
future.thenRun(() -> {
if (fresh) {
final SimpleTextInput newCache = new SimpleTextInput();
newCache.getLines().add(tlLiteral("serverTotal", NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess)));
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("serverTotal", NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess))));
int pos = 1;
for (final Map.Entry<UUID, BalanceTop.Entry> entry : ess.getBalanceTop().getBalanceTopCache().entrySet()) {
if (ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) {
newCache.getLines().add(tlLiteral("balanceTopLine", pos, AdventureUtil.parsed(AdventureUtil.legacyToMini(entry.getValue().getDisplayName())), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess)));
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess))));
}
pos++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.PlayerList;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.AdventureUtil;
import org.bukkit.Server;

import java.util.ArrayList;
Expand All @@ -23,11 +24,11 @@ public void run(final Server server, final CommandSource sender, final String co
user = ess.getUser(sender.getPlayer());
showHidden = user.isAuthorized("essentials.list.hidden") || user.canInteractVanished();
}
sender.sendMessage(PlayerList.listSummary(ess, user, showHidden));
sender.sendComponent(AdventureUtil.miniMessage().deserialize(PlayerList.listSummary(ess, user, showHidden)));
final Map<String, List<User>> playerList = PlayerList.getPlayerLists(ess, user, showHidden);

if (args.length > 0) {
sender.sendMessage(PlayerList.listGroupUsers(ess, playerList, args[0].toLowerCase()));
sender.sendComponent(AdventureUtil.miniMessage().deserialize(PlayerList.listGroupUsers(ess, playerList, args[0].toLowerCase())));
} else {
sendGroupedList(sender, commandLabel, playerList);
}
Expand All @@ -36,7 +37,7 @@ public void run(final Server server, final CommandSource sender, final String co
// Output the standard /list output, when no group is specified
private void sendGroupedList(final CommandSource sender, final String commandLabel, final Map<String, List<User>> playerList) {
for (final String str : PlayerList.prepareGroupedList(ess, sender, commandLabel, playerList)) {
sender.sendMessage(str);
sender.sendComponent(AdventureUtil.miniMessage().deserialize(str));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.earth2me.essentials.IUser;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.CommonPlaceholders;
import net.ess3.api.events.PrivateMessagePreSendEvent;
import net.ess3.api.events.PrivateMessageSentEvent;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -128,9 +127,9 @@ public MessageResponse sendMessage(final IMessageRecipient recipient, String mes
&& !onlineUser.equals(senderUser)
&& !onlineUser.equals(recipient)) {
if (senderUser.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers()) {
onlineUser.sendMessage(tlSender("socialSpyMutedPrefix") + tlLiteral("socialSpyMsgFormat", CommonPlaceholders.displayNameRecipient(this), CommonPlaceholders.displayNameRecipient(recipient), message));
onlineUser.sendComponent(AdventureUtil.miniMessage().deserialize(tlSender("socialSpyMutedPrefix") + tlLiteral("socialSpyMsgFormat", getDisplayName(), recipient.getDisplayName(), message)));
} else {
onlineUser.sendMessage(tlLiteral("socialSpyPrefix") + tlLiteral("socialSpyMsgFormat", CommonPlaceholders.displayNameRecipient(this), CommonPlaceholders.displayNameRecipient(recipient), message));
onlineUser.sendComponent(AdventureUtil.miniMessage().deserialize(tlLiteral("socialSpyPrefix") + tlLiteral("socialSpyMsgFormat", getDisplayName(), recipient.getDisplayName(), message)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.AdventureUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.MaterialUtil;
import com.earth2me.essentials.utils.NumberUtil;
Expand Down Expand Up @@ -103,7 +104,7 @@ protected final boolean onSignCreate(final SignChangeEvent event, final IEssenti
// they won't change it to §1[Signname]
return true;
}
sign.setLine(0, tlLiteral("signFormatFail", this.signName));
sign.setLine(0, AdventureUtil.miniToLegacy(tlLiteral("signFormatFail", this.signName)));

final SignCreateEvent signEvent = new SignCreateEvent(sign, this, user);
ess.getServer().getPluginManager().callEvent(signEvent);
Expand Down Expand Up @@ -137,7 +138,7 @@ public String getSuccessName(final IEssentials ess) {
}

public String getSuccessName() {
String successName = tlLiteral("signFormatSuccess", this.signName);
String successName = AdventureUtil.miniToLegacy(tlLiteral("signFormatSuccess", this.signName));
if (successName.isEmpty() || !successName.contains(this.signName)) {
// Set to null to cause an error in place of no functionality. This makes an error obvious as opposed to leaving users baffled by lack of
// functionality.
Expand All @@ -147,7 +148,7 @@ public String getSuccessName() {
}

public String getTemplateName() {
return tlLiteral("signFormatTemplate", this.signName);
return AdventureUtil.miniToLegacy(tlLiteral("signFormatTemplate", this.signName));
}

public String getName() {
Expand Down Expand Up @@ -407,7 +408,7 @@ protected final ItemStack getItemStack(final String itemName, final int quantity
item.setAmount(quantity);
return item;
} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
}

Expand All @@ -425,7 +426,7 @@ protected final ItemStack getItemMeta(final CommandSource source, final ItemStac
stack = metaStack.getItemStack();
}
} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
return stack;
}
Expand All @@ -447,7 +448,7 @@ protected final BigDecimal getBigDecimal(final String line, final IEssentials es
try {
return new BigDecimal(NumberUtil.sanitizeCurrencyString(line, ess));
} catch (final ArithmeticException | NumberFormatException ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
level = Integer.parseInt(enchantLevel[1]);
} catch (final NumberFormatException ex) {
sign.setLine(2, "§c<enchant>");
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
}
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments() && player.isAuthorized("essentials.enchantments.allowunsafe") && player.isAuthorized("essentials.signs.enchant.allowunsafe");
Expand All @@ -57,7 +57,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
}
}
} catch (final Throwable ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
getTrade(sign, 3, ess);
return true;
Expand All @@ -81,7 +81,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
try {
level = Integer.parseInt(enchantLevel[1]);
} catch (final NumberFormatException ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
}

Expand All @@ -103,7 +103,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
}
}
} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}

final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
item = getItemMeta(item, sign.getLine(3), ess);
} catch (final SignException ex) {
sign.setLine(1, "§c<item>");
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
pager.showPage(chapter, page, null, player.getSource());

} catch (final IOException ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}

charge.charge(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
try {
ess.getKits().getKit(kitName);
} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
final String group = sign.getLine(2);
if ("Everyone".equalsIgnoreCase(group) || "Everybody".equalsIgnoreCase(group)) {
Expand Down Expand Up @@ -55,7 +55,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
} catch (final NoChargeException ex) {
return false;
} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
}

} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}

charge.charge(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected boolean onSignInteract(final ISign sign, final User player, final Stri
final List<String> mobData = SpawnMob.mobData(sign.getLine(2));
SpawnMob.spawnmob(ess, ess.getServer(), player.getSource(), player, mobParts, mobData, Integer.parseInt(sign.getLine(1)));
} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}

charge.charge(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String
try {
ess.getWarps().getWarp(warpName);
} catch (final Exception ex) {
throw new SignException(ex, ex.getMessage());
throw new SignException(ex, "errorWithMessage", ex.getMessage());
}
final String group = sign.getLine(2);
if ("Everyone".equalsIgnoreCase(group) || "Everybody".equalsIgnoreCase(group)) {
Expand Down

0 comments on commit 16e2972

Please sign in to comment.