diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java index 3160f01..5f282c7 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java @@ -48,6 +48,8 @@ public class Messages { public static String YOU_CANNOT_CREATE_SHOP = "You can't create this type of shop!"; public static String NO_CHEST_DETECTED = "Couldn't find a chest!"; public static String INVALID_SHOP_DETECTED = "The shop cannot be used!"; + public static String INVALID_SHOP_PRICE = "The shop has an invalid price!"; + public static String INVALID_SHOP_QUANTITY = "The shop has an invalid quantity!"; public static String CANNOT_ACCESS_THE_CHEST = "You don't have permissions to access this chest!"; @PrecededBySpace diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index ad5c16c..7b56813 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -72,6 +72,10 @@ public class Properties { @ConfigurationComment("Should we block shops that sell things for more than they buy? (This prevents newbies from creating shops that would be exploited)") public static boolean BLOCK_SHOPS_WITH_SELL_PRICE_HIGHER_THAN_BUY_PRICE = true; + @PrecededBySpace + @ConfigurationComment("Maximum amount of items that can be bought/sold at a shop. Default 3456 is a double chest of 64 stacks.") + public static int MAX_SHOP_AMOUNT = 3456; + @PrecededBySpace @ConfigurationComment("Do you want to allow other players to build a shop on a block where there's one already?") public static boolean ALLOW_MULTIPLE_SHOPS_AT_ONE_BLOCK = false; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java index ef5fd24..c6656ac 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -168,10 +168,14 @@ public class PlayerInteract implements Listener { return null; } - int amount = Integer.parseInt(quantity); + int amount = -1; + try { + amount = Integer.parseInt(quantity); + } catch (NumberFormatException notANumber) {} - if (amount < 1) { - amount = 1; + if (amount < 1 || amount > Properties.MAX_SHOP_AMOUNT) { + player.sendMessage(Messages.prefix(Messages.INVALID_SHOP_PRICE)); + return null; } if (Properties.SHIFT_SELLS_IN_STACKS && player.isSneaking() && price != PriceUtil.NO_PRICE && isAllowedForShift(action == buy)) { diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java index 7815acc..37ef334 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java @@ -24,10 +24,10 @@ public class ErrorMessageSender implements Listener { message = Messages.INCORRECT_ITEM_ID; break; case INVALID_PRICE: - message = Messages.INVALID_SHOP_DETECTED; + message = Messages.INVALID_SHOP_PRICE; break; case INVALID_QUANTITY: - message = Messages.INVALID_SHOP_DETECTED; + message = Messages.INVALID_SHOP_QUANTITY; break; case SELL_PRICE_HIGHER_THAN_BUY_PRICE: message = Messages.YOU_CANNOT_CREATE_SHOP; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java index 50053b7..2d93841 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/QuantityChecker.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Listeners.PreShopCreation; -import com.Acrobot.Breeze.Utils.NumberUtil; +import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -16,9 +16,12 @@ public class QuantityChecker implements Listener { @EventHandler(priority = EventPriority.LOWEST) public static void onPreShopCreation(PreShopCreationEvent event) { - String quantity = event.getSignLine(QUANTITY_LINE); + int amount = -1; + try { + amount = Integer.parseInt(event.getSignLine(QUANTITY_LINE)); + } catch (NumberFormatException notANumber) {} - if (!NumberUtil.isInteger(quantity)) { + if (amount < 1 || amount > Properties.MAX_SHOP_AMOUNT) { event.setOutcome(INVALID_QUANTITY); } } diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index 96aa5a5..114d1d4 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -27,7 +27,7 @@ public class ChestShopSign { public static final Pattern[] SHOP_SIGN_PATTERN = { Pattern.compile("^?[\\w -.:]*$"), - Pattern.compile("^[1-9][0-9]*$"), + Pattern.compile("^[1-9][0-9]{0,6}$"), Pattern.compile("(?i)^[\\d.bs(free) :]+$"), Pattern.compile("^[\\w? #:-]+$") };