From ac71113f3e490d23c73469eab1a0e5fd9e07782a Mon Sep 17 00:00:00 2001 From: Acrobot Date: Sat, 3 Nov 2012 20:41:28 +0100 Subject: [PATCH] Added protection from buy and sell prices == 0 Also fixed the formattedItem NPE. --- com/Acrobot/ChestShop/Listeners/Block/SignChange.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/com/Acrobot/ChestShop/Listeners/Block/SignChange.java b/com/Acrobot/ChestShop/Listeners/Block/SignChange.java index 54b2476..7245b64 100644 --- a/com/Acrobot/ChestShop/Listeners/Block/SignChange.java +++ b/com/Acrobot/ChestShop/Listeners/Block/SignChange.java @@ -106,6 +106,11 @@ public class SignChange implements Listener { double buyPrice = PriceUtil.getBuyPrice(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()))) { sendMessageAndExit(YOU_CANNOT_CREATE_SHOP, event); return; @@ -180,7 +185,7 @@ public class SignChange implements Listener { return true; } - if (buy && !Permission.has(player, Permission.SHOP_CREATION_BUY)){ + if (buy && !Permission.has(player, Permission.SHOP_CREATION_BUY)) { return false; } else { 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())); } - if (MaterialUtil.getItem(formatted).getType() != item.getType()) { + ItemStack formattedItem = MaterialUtil.getItem(formatted); + + if (formattedItem == null || formattedItem.getType() != item.getType()) { formatted = String.valueOf(item.getTypeId()); }