summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-01-04 18:56:36 +0000
committerKHobbits <rob@khobbits.co.uk>2012-01-04 18:56:36 +0000
commita46f6fd73decdc47e5c2bf29c563d0deb20f0735 (patch)
tree7d9bf9d9d2d40ee929448c1b129881b9d1110a5c
parent897571db7d838f0f2ff86cfb40b59fd0349f4974 (diff)
downloadEssentials-a46f6fd73decdc47e5c2bf29c563d0deb20f0735.tar
Essentials-a46f6fd73decdc47e5c2bf29c563d0deb20f0735.tar.gz
Essentials-a46f6fd73decdc47e5c2bf29c563d0deb20f0735.tar.lz
Essentials-a46f6fd73decdc47e5c2bf29c563d0deb20f0735.tar.xz
Essentials-a46f6fd73decdc47e5c2bf29c563d0deb20f0735.zip
Revert "Possible sign refactor?"
This reverts commit 897571db7d838f0f2ff86cfb40b59fd0349f4974.
-rw-r--r--Essentials/src/com/earth2me/essentials/Trade.java30
-rw-r--r--Essentials/src/com/earth2me/essentials/user/User.java2
-rw-r--r--EssentialsSigns/src/com/earth2me/essentials/signs/SignBuy.java5
-rw-r--r--EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java5
4 files changed, 28 insertions, 14 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Trade.java b/Essentials/src/com/earth2me/essentials/Trade.java
index bcfd35d35..f92a1d504 100644
--- a/Essentials/src/com/earth2me/essentials/Trade.java
+++ b/Essentials/src/com/earth2me/essentials/Trade.java
@@ -96,32 +96,38 @@ public class Trade
}
public void pay(final IUser user)
- {
- try
- {
- pay(user, true);
- }
- catch (ChargeException ex)
- {
- //This should never ever get here... true above means items get dropped.
- user.sendMessage(ex.getMessage());
- }
+ {
+ pay(user, true);
}
- public void pay(final IUser user, final boolean dropItems) throws ChargeException
+ public boolean pay(final IUser user, final boolean dropItems)
{
+ boolean success = true;
if (getMoney() != null && getMoney() > 0)
{
user.giveMoney(getMoney());
}
if (getItemStack() != null)
{
- user.giveItems(itemStack, dropItems);
+ if (dropItems)
+ {
+ final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItem(user.getInventory(), true, getItemStack());
+ for (ItemStack itemStack : leftOver.values())
+ {
+ InventoryWorkaround.dropItem(user.getLocation(), itemStack);
+ }
+ }
+ else
+ {
+ success = InventoryWorkaround.addAllItems(user.getInventory(), true, getItemStack());
+ }
+ user.updateInventory();
}
if (getExperience() != null)
{
SetExpFix.setTotalExperience(user, SetExpFix.getTotalExperience(user) + getExperience());
}
+ return success;
}
public void charge(final IUser user) throws ChargeException
diff --git a/Essentials/src/com/earth2me/essentials/user/User.java b/Essentials/src/com/earth2me/essentials/user/User.java
index 1d209df18..cc461598d 100644
--- a/Essentials/src/com/earth2me/essentials/user/User.java
+++ b/Essentials/src/com/earth2me/essentials/user/User.java
@@ -661,6 +661,7 @@ public class User extends UserBase implements IUser
{
sendMessage(_("InvFull"));
}
+ updateInventory();
}
@Override
@@ -678,6 +679,7 @@ public class User extends UserBase implements IUser
{
sendMessage(_("InvFull"));
}
+ updateInventory();
}
private boolean giveItemStack(ItemStack itemStack, Boolean canSpew) throws ChargeException
diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignBuy.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignBuy.java
index 628ed64c1..fd84bd0f3 100644
--- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignBuy.java
+++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignBuy.java
@@ -27,7 +27,10 @@ public class SignBuy extends EssentialsSign
final Trade items = getTrade(sign, 1, 2, player, ess);
final Trade charge = getTrade(sign, 3, ess);
charge.isAffordableFor(player);
- items.pay(player, false);
+ if (!items.pay(player, false))
+ {
+ throw new ChargeException("Inventory full");
+ }
charge.charge(player);
Trade.log("Sign", "Buy", "Interact", username, charge, username, items, sign.getBlock().getLocation(), ess);
return true;
diff --git a/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java b/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java
index df913eced..04db5511c 100644
--- a/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java
+++ b/EssentialsSigns/src/com/earth2me/essentials/signs/SignTrade.java
@@ -55,7 +55,10 @@ 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);
- trade.pay(player, false);
+ if (!trade.pay(player, false))
+ {
+ throw new ChargeException("Full inventory");
+ }
substractAmount(sign, 2, trade, ess);
addAmount(sign, 1, charge, ess);
charge.charge(player);