diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java index 391842a..bfd82cb 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 6e55895..7b1813f 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -154,6 +154,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 b61fdfc..39c267f 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -182,15 +182,19 @@ public class PlayerInteract implements Listener { ItemParseEvent parseEvent = new ItemParseEvent(material); Bukkit.getPluginManager().callEvent(parseEvent); ItemStack item = parseEvent.getItem(); - if (item == null || !NumberUtil.isInteger(quantity)) { + if (item == null) { player.sendMessage(Messages.prefix(Messages.INVALID_SHOP_DETECTED)); 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.equals(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 02ea929..f960f50 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java @@ -27,10 +27,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 ba2485e..0b6a661 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -33,7 +33,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? #:-]+$") };