From 2d56de1483a8dbd75cba146fae4a0dbe4270b1e3 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 11 Feb 2012 21:15:26 +0000 Subject: Update trade signs properly, and visibly handle full signs. --- .../src/com/earth2me/essentials/signs/SignTrade.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java index 943a14a83..6b47ebc76 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java @@ -36,7 +36,7 @@ public class SignTrade extends EssentialsSign try { stored = getTrade(sign, 1, true, true, ess); - substractAmount(sign, 1, stored, ess); + subtractAmount(sign, 1, stored, ess); stored.pay(player); } catch (SignException e) @@ -53,12 +53,14 @@ public class SignTrade extends EssentialsSign final Trade charge = getTrade(sign, 1, false, false, ess); final Trade trade = getTrade(sign, 2, false, true, ess); charge.isAffordableFor(player); + addAmount(sign, 1, charge, ess); + subtractAmount(sign, 2, trade, ess); if (!trade.pay(player, false)) { + subtractAmount(sign, 1, charge, ess); + addAmount(sign, 2, trade, ess); throw new ChargeException("Full inventory"); } - substractAmount(sign, 2, trade, ess); - addAmount(sign, 1, charge, ess); charge.charge(player); Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, sign.getBlock().getLocation(), ess); } @@ -256,7 +258,7 @@ public class SignTrade extends EssentialsSign throw new SignException(_("invalidSignLine", index + 1)); } - protected final void substractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException + protected final void subtractAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException { final Double money = trade.getMoney(); if (money != null) @@ -294,6 +296,7 @@ public class SignTrade extends EssentialsSign } } + //TODO: Translate these exceptions. private void changeAmount(final ISign sign, final int index, final double value, final IEssentials ess) throws SignException { @@ -313,7 +316,7 @@ public class SignTrade extends EssentialsSign final String newline = Util.formatCurrency(money, ess) + ":" + Util.formatCurrency(amount + value, ess).substring(1); if (newline.length() > 15) { - throw new SignException("Line too long!"); + throw new SignException("This sign is full: Line too long!"); } sign.setLine(index, newline); return; @@ -329,7 +332,7 @@ public class SignTrade extends EssentialsSign final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value)); if (newline.length() > 15) { - throw new SignException("Line too long!"); + throw new SignException("This sign is full: Line too long!"); } sign.setLine(index, newline); return; @@ -343,7 +346,7 @@ public class SignTrade extends EssentialsSign final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value)); if (newline.length() > 15) { - throw new SignException("Line too long!"); + throw new SignException("This sign is full: Line too long!"); } sign.setLine(index, newline); return; -- cgit v1.2.3