Really fixed Admin Shops now

This commit is contained in:
Acrobot 2012-09-15 20:32:22 +02:00
parent 773ae17118
commit 773df3bbc3
6 changed files with 16 additions and 36 deletions

View File

@ -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));
}

View File

@ -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();
}
}

View File

@ -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()) {

View File

@ -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) {

View File

@ -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(" ", ""));
}

View File

@ -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/