summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-10-09 22:52:11 +0200
committersnowleo <schneeleo@gmail.com>2011-10-09 22:52:11 +0200
commit4c694125014659ebb02b8cd910e547ed69eb50c0 (patch)
treeb6857aaf48e303c30d3726d67e3ac33157dd52a5
parent75a0164ea0dcd373e3a574faaea554fd4102ab9b (diff)
downloadEssentials-4c694125014659ebb02b8cd910e547ed69eb50c0.tar
Essentials-4c694125014659ebb02b8cd910e547ed69eb50c0.tar.gz
Essentials-4c694125014659ebb02b8cd910e547ed69eb50c0.tar.lz
Essentials-4c694125014659ebb02b8cd910e547ed69eb50c0.tar.xz
Essentials-4c694125014659ebb02b8cd910e547ed69eb50c0.zip
Allow players to recharge trade signs without breaking them.
Also don't give out items, if their inventory is full.
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignTrade.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
index c19d19178..6e5c7b4b1 100644
--- a/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
+++ b/Essentials/src/com/earth2me/essentials/signs/SignTrade.java
@@ -38,7 +38,8 @@ public class SignTrade extends EssentialsSign
final Trade stored = getTrade(sign, 1, true, true, ess);
substractAmount(sign, 1, stored, ess);
stored.pay(player);
- Trade.log("Sign", "Trade", "OwnerInteract", username, null, username, stored, sign.getBlock().getLocation(), ess);
+ final Trade store = rechargeSign(sign, ess, player);
+ Trade.log("Sign", "Trade", "OwnerInteract", username, store, username, stored, sign.getBlock().getLocation(), ess);
}
catch (SignException e)
{
@@ -50,8 +51,11 @@ 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);
+ if (!trade.pay(player, false))
+ {
+ throw new ChargeException("Full inventory");
+ }
substractAmount(sign, 2, trade, ess);
- trade.pay(player);
addAmount(sign, 1, charge, ess);
charge.charge(player);
Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, sign.getBlock().getLocation(), ess);
@@ -60,6 +64,25 @@ public class SignTrade extends EssentialsSign
return true;
}
+ private Trade rechargeSign(final ISign sign, final IEssentials ess, final User player) throws SignException, ChargeException
+ {
+ final Trade trade = getTrade(sign, 2, false, false, ess);
+ if (trade.getItemStack() != null && player.getItemInHand() != null &&
+ trade.getItemStack().getTypeId() == player.getItemInHand().getTypeId() &&
+ trade.getItemStack().getDurability() == player.getItemInHand().getDurability())
+ {
+ int amount = player.getItemInHand().getAmount();
+ amount -= amount % trade.getItemStack().getAmount();
+ if (amount > 0) {
+ final Trade store = new Trade(new ItemStack(player.getItemInHand().getTypeId(), amount, player.getItemInHand().getDurability()), ess);
+ addAmount(sign, 2, store, ess);
+ store.charge(player);
+ return store;
+ }
+ }
+ return null;
+ }
+
@Override
protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
{