mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-09-27 14:13:05 +02:00
Add ability to set max amount and improve error messages
This commit is contained in:
parent
39d1c13491
commit
f2db944aa7
@ -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
|
||||
|
@ -75,6 +75,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;
|
||||
|
@ -170,10 +170,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)) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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? #:-]+$")
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user