Fixed bug that caused non-economically-active admin shops to be out of money. Also, fixed probable bug with enchantments

This commit is contained in:
Acrobot 2012-09-14 23:00:17 +02:00
parent 6707b1bd5e
commit 228f493b70
3 changed files with 32 additions and 2 deletions

View File

@ -241,7 +241,7 @@ public class MaterialUtil {
* @return Enchantments found
*/
public static Map<org.bukkit.enchantments.Enchantment, Integer> getEnchantments(String base32) {
if (base32 == null || base32.isEmpty()) {
if (base32 == null || base32.isEmpty() || !NumberUtil.isLong(base32)) {
return new HashMap<org.bukkit.enchantments.Enchantment, Integer>();
}

View File

@ -64,6 +64,21 @@ public class NumberUtil {
}
}
/**
* Checks if the string is a long
*
* @param string string to check
* @return Is the string long?
*/
public static boolean isLong(String string) {
try {
Long.parseLong(string);
return true;
} catch (NumberFormatException e) {
return false;
}
}
/**
* Rounds the number up to two decimal points (Can be inaccurate due to using decimal-points)
*

View File

@ -1,6 +1,9 @@
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;
@ -44,7 +47,7 @@ public class AmountAndPriceChecker implements Listener {
ItemStack[] stock = event.getStock();
Inventory clientInventory = event.getClientInventory();
if (!Economy.hasEnough(event.getOwner().getName(), event.getPrice())) {
if (isOwnerEconomicalyActive(event) && !Economy.hasEnough(event.getOwner().getName(), event.getPrice())) {
event.setCancelled(SHOP_DOES_NOT_HAVE_ENOUGH_MONEY);
return;
}
@ -54,6 +57,18 @@ 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()) {