Added protection from buy and sell prices == 0

Also fixed the formattedItem NPE.
This commit is contained in:
Acrobot 2012-11-03 20:41:28 +01:00
parent 45fa6d5c75
commit ac71113f3e

View File

@ -106,6 +106,11 @@ public class SignChange implements Listener {
double buyPrice = PriceUtil.getBuyPrice(formattedPrice); double buyPrice = PriceUtil.getBuyPrice(formattedPrice);
double sellPrice = PriceUtil.getSellPrice(formattedPrice); double sellPrice = PriceUtil.getSellPrice(formattedPrice);
if (buyPrice == 0 && sellPrice == 0) {
sendMessageAndExit(YOU_CANNOT_CREATE_SHOP, event);
return;
}
if (!isAdmin && (!canCreateShop(player, stock.getType(), buyPrice, sellPrice) || !MaxPrice.canCreate(buyPrice, sellPrice, stock.getType()))) { if (!isAdmin && (!canCreateShop(player, stock.getType(), buyPrice, sellPrice) || !MaxPrice.canCreate(buyPrice, sellPrice, stock.getType()))) {
sendMessageAndExit(YOU_CANNOT_CREATE_SHOP, event); sendMessageAndExit(YOU_CANNOT_CREATE_SHOP, event);
return; return;
@ -180,7 +185,7 @@ public class SignChange implements Listener {
return true; return true;
} }
if (buy && !Permission.has(player, Permission.SHOP_CREATION_BUY)){ if (buy && !Permission.has(player, Permission.SHOP_CREATION_BUY)) {
return false; return false;
} else { } else {
return !(sell && !Permission.has(player, Permission.SHOP_CREATION_SELL)); return !(sell && !Permission.has(player, Permission.SHOP_CREATION_SELL));
@ -228,7 +233,9 @@ public class SignChange implements Listener {
formatted = formatted.substring(0, (15 - data.length())); formatted = formatted.substring(0, (15 - data.length()));
} }
if (MaterialUtil.getItem(formatted).getType() != item.getType()) { ItemStack formattedItem = MaterialUtil.getItem(formatted);
if (formattedItem == null || formattedItem.getType() != item.getType()) {
formatted = String.valueOf(item.getTypeId()); formatted = String.valueOf(item.getTypeId());
} }