From 773df3bbc3686bf9649b94ee7cb6cf8f7f81d038 Mon Sep 17 00:00:00 2001 From: Acrobot Date: Sat, 15 Sep 2012 20:32:22 +0200 Subject: [PATCH] Really fixed Admin Shops now --- com/Acrobot/ChestShop/Economy/Economy.java | 5 +++++ .../PostTransaction/EconomicModule.java | 20 ++----------------- .../PreTransaction/AmountAndPriceChecker.java | 17 +--------------- .../PartialTransactionModule.java | 2 +- .../ChestShop/Signs/ChestShopSign.java | 6 ++++++ plugin.yml | 2 +- 6 files changed, 16 insertions(+), 36 deletions(-) diff --git a/com/Acrobot/ChestShop/Economy/Economy.java b/com/Acrobot/ChestShop/Economy/Economy.java index 8af0e96..3f9450d 100644 --- a/com/Acrobot/ChestShop/Economy/Economy.java +++ b/com/Acrobot/ChestShop/Economy/Economy.java @@ -5,6 +5,7 @@ import com.Acrobot.ChestShop.Config.Config; import com.Acrobot.ChestShop.Config.Property; import com.Acrobot.ChestShop.Signs.ChestShopSign; import com.Acrobot.ChestShop.Utils.uName; +import org.bukkit.inventory.Inventory; import static com.Acrobot.Breeze.Utils.NumberUtil.roundUp; @@ -15,6 +16,10 @@ import static com.Acrobot.Breeze.Utils.NumberUtil.roundUp; public class Economy { private static EcoPlugin economy; + public static boolean isOwnerEconomicallyActive(Inventory inventory) { + return !ChestShopSign.isAdminShop(inventory) || getServerAccountName().isEmpty(); + } + public static boolean hasAccount(String p) { return !p.isEmpty() && economy.hasAccount(uName.getName(p)); } diff --git a/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java b/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java index bc50ea3..08ad13c 100644 --- a/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java +++ b/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java @@ -1,13 +1,9 @@ package com.Acrobot.ChestShop.Listeners.PostTransaction; -import com.Acrobot.ChestShop.Config.Config; -import com.Acrobot.ChestShop.Config.Property; -import com.Acrobot.ChestShop.Containers.AdminInventory; import com.Acrobot.ChestShop.Economy.Economy; import com.Acrobot.ChestShop.Events.TransactionEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.inventory.Inventory; import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY; import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.SELL; @@ -22,7 +18,7 @@ public class EconomicModule implements Listener { return; } - if (isOwnerEconomicalyActive(event)) { + if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory())) { Economy.add(event.getOwner().getName(), event.getPrice()); } @@ -35,22 +31,10 @@ public class EconomicModule implements Listener { return; } - if (isOwnerEconomicalyActive(event)) { + if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory())) { Economy.subtract(event.getOwner().getName(), event.getPrice()); } Economy.add(event.getClient().getName(), event.getPrice()); } - - public static String getServerAccountName() { - return Config.getString(Property.SERVER_ECONOMY_ACCOUNT); - } - - public static boolean isServerShop(Inventory inventory) { - return inventory instanceof AdminInventory; - } - - public static boolean isOwnerEconomicalyActive(TransactionEvent event) { - return !isServerShop(event.getOwnerInventory()) || !getServerAccountName().isEmpty(); - } } diff --git a/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java b/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java index 14f654f..c972e0d 100644 --- a/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java +++ b/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java @@ -1,9 +1,6 @@ package com.Acrobot.ChestShop.Listeners.PreTransaction; import com.Acrobot.Breeze.Utils.InventoryUtil; -import com.Acrobot.ChestShop.Config.Config; -import com.Acrobot.ChestShop.Config.Property; -import com.Acrobot.ChestShop.Containers.AdminInventory; import com.Acrobot.ChestShop.Economy.Economy; import com.Acrobot.ChestShop.Events.PreTransactionEvent; import org.bukkit.event.EventHandler; @@ -47,7 +44,7 @@ public class AmountAndPriceChecker implements Listener { ItemStack[] stock = event.getStock(); Inventory clientInventory = event.getClientInventory(); - if (isOwnerEconomicalyActive(event) && !Economy.hasEnough(event.getOwner().getName(), event.getPrice())) { + if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory()) && !Economy.hasEnough(event.getOwner().getName(), event.getPrice())) { event.setCancelled(SHOP_DOES_NOT_HAVE_ENOUGH_MONEY); return; } @@ -57,18 +54,6 @@ public class AmountAndPriceChecker implements Listener { } } - public static String getServerAccountName() { - return Config.getString(Property.SERVER_ECONOMY_ACCOUNT); - } - - public static boolean isServerShop(Inventory inventory) { - return inventory instanceof AdminInventory; - } - - public static boolean isOwnerEconomicalyActive(PreTransactionEvent event) { - return !isServerShop(event.getOwnerInventory()) || !getServerAccountName().isEmpty(); - } - private static boolean hasItems(Inventory inventory, ItemStack[] items) { for (ItemStack item : items) { if (InventoryUtil.getAmount(item, inventory) < item.getAmount()) { diff --git a/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java b/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java index 241555c..41f928f 100644 --- a/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java +++ b/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java @@ -77,7 +77,7 @@ public class PartialTransactionModule implements Listener { double pricePerItem = event.getPrice() / getItemCount(stock); double walletMoney = Economy.getBalance(ownerName); - if (!Economy.hasEnough(ownerName, price)) { + if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory()) && !Economy.hasEnough(ownerName, price)) { int amountAffordable = getAmountOfAffordableItems(walletMoney, pricePerItem); if (amountAffordable < 1) { diff --git a/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/com/Acrobot/ChestShop/Signs/ChestShopSign.java index 2be6afa..89a35e1 100644 --- a/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -2,10 +2,12 @@ package com.Acrobot.ChestShop.Signs; import com.Acrobot.Breeze.Utils.BlockUtil; import com.Acrobot.ChestShop.Config.Config; +import com.Acrobot.ChestShop.Containers.AdminInventory; import com.Acrobot.ChestShop.Utils.uName; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import java.util.regex.Pattern; @@ -27,6 +29,10 @@ public class ChestShopSign { Pattern.compile("[\\w : -]+") }; + public static boolean isAdminShop(Inventory ownerInventory) { + return ownerInventory instanceof AdminInventory; + } + public static boolean isAdminShop(String owner) { return owner.replace(" ", "").equalsIgnoreCase(Config.getString(ADMIN_SHOP_NAME).replace(" ", "")); } diff --git a/plugin.yml b/plugin.yml index 2f9c102..912a323 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ChestShop main: com.Acrobot.ChestShop.ChestShop -version: 3.50t0009 +version: 3.50t0010 #for CButD dev-url: http://dev.bukkit.org/server-mods/chestshop/