From ac953cd1148427c5555242958a1dff62b5b0bbcd Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 5 Oct 2020 02:47:12 -0600 Subject: [PATCH] Remove sign color codes from trade.log (#3699) Started looking into #3116 but noticed this issue and wanted to fix it first. Also added a comment as to why the username is truncated as this took me a long time to figure out and seemed arbitrary. Probably could truncate the username later for trade signs only as other signs don't require any username to be present on the sign. However, for now I simply opted to document. --- .../com/earth2me/essentials/signs/EssentialsSign.java | 1 + .../src/com/earth2me/essentials/signs/SignTrade.java | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index a86c7cc39..22fb60776 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -150,6 +150,7 @@ public class EssentialsSign { } public String getUsername(final User user) { + // Truncate username to ensure it can fit on a sign return user.getName().substring(0, Math.min(user.getName().length(), 13)); } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index bbeb54a50..c2c9f03e7 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -73,7 +73,7 @@ public class SignTrade extends EssentialsSign { throw new ChargeException("Full inventory"); } charge.charge(player); - Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, sign.getBlock().getLocation(), ess); + Trade.log("Sign", "Trade", "Interact", sign.getLine(3).substring(2), charge, username, trade, sign.getBlock().getLocation(), ess); } sign.updateSign(); return true; @@ -110,7 +110,7 @@ public class SignTrade extends EssentialsSign { final Trade stored2 = getTrade(sign, 2, AmountType.TOTAL, false, true, ess); if (!canCollect) { - Trade.log("Sign", "Trade", "Destroy", signOwner, stored2, username, stored1, sign.getBlock().getLocation(), ess); + Trade.log("Sign", "Trade", "Destroy", signOwner.substring(2), stored2, username, stored1, sign.getBlock().getLocation(), ess); return true; } @@ -118,15 +118,15 @@ public class SignTrade extends EssentialsSign { final Map withdraw2 = stored2.pay(player, OverflowType.RETURN); if (withdraw1 == null && withdraw2 == null) { - Trade.log("Sign", "Trade", "Break", signOwner, stored2, username, stored1, sign.getBlock().getLocation(), ess); + Trade.log("Sign", "Trade", "Break", signOwner.substring(2), stored2, username, stored1, sign.getBlock().getLocation(), ess); return true; } setAmount(sign, 1, BigDecimal.valueOf(withdraw1 == null ? 0L : withdraw1.get(0).getAmount()), ess); - Trade.log("Sign", "Trade", "Withdraw", signOwner, stored1, username, withdraw1 == null ? null : new Trade(withdraw1.get(0), ess), sign.getBlock().getLocation(), ess); + Trade.log("Sign", "Trade", "Withdraw", signOwner.substring(2), stored1, username, withdraw1 == null ? null : new Trade(withdraw1.get(0), ess), sign.getBlock().getLocation(), ess); setAmount(sign, 2, BigDecimal.valueOf(withdraw2 == null ? 0L : withdraw2.get(0).getAmount()), ess); - Trade.log("Sign", "Trade", "Withdraw", signOwner, stored2, username, withdraw2 == null ? null : new Trade(withdraw2.get(0), ess), sign.getBlock().getLocation(), ess); + Trade.log("Sign", "Trade", "Withdraw", signOwner.substring(2), stored2, username, withdraw2 == null ? null : new Trade(withdraw2.get(0), ess), sign.getBlock().getLocation(), ess); sign.updateSign(); } catch (final SignException e) {