mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-26 02:19:48 -05:00
Fix #977, handle infinite and nan value
This commit is contained in:
1 parent
2424fcce12
commit
e3f670ff7f
4 files changed
+35
-18
No files matched your search
@@ -60,25 +60,31 @@ public class SubCommand_Price implements CommandProcesser {
|
||||
final double price;
|
||||
final double minPrice = plugin.getConfig().getDouble("shop.minimum-price");
|
||||
|
||||
try { //TODO Migrate to PriceLimiter
|
||||
if (plugin.getConfig().getBoolean("whole-number-prices-only")) {
|
||||
try {
|
||||
price = Long.parseLong(cmdArg[0]);
|
||||
} catch (NumberFormatException ex2) {
|
||||
// input is number, but not Integer
|
||||
Util.debugLog(ex2.getMessage());
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("not-a-integer", p, cmdArg[0]));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
price = Double.parseDouble(cmdArg[0]);
|
||||
//TODO Migrate to PriceLimiter
|
||||
if (plugin.getConfig().getBoolean("whole-number-prices-only")) {
|
||||
try {
|
||||
price = Long.parseLong(cmdArg[0]);
|
||||
} catch (NumberFormatException ex2) {
|
||||
// input is number, but not Integer
|
||||
Util.debugLog(ex2.getMessage());
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("not-a-integer", p, cmdArg[0]));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
price = Double.parseDouble(cmdArg[0]);
|
||||
|
||||
} catch (NumberFormatException ex) {
|
||||
} catch (NumberFormatException ex) {
|
||||
// No number input
|
||||
Util.debugLog(ex.getMessage());
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("not-a-number", p, cmdArg[0]));
|
||||
return;
|
||||
}
|
||||
// No number input
|
||||
Util.debugLog(ex.getMessage());
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("not-a-number", p, cmdArg[0]));
|
||||
return;
|
||||
if (Double.isInfinite(price) || Double.isNaN(price)) {
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("not-a-number", p, cmdArg[0]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final boolean format = plugin.getConfig().getBoolean("use-decimal-format");
|
||||
|
||||
@@ -874,7 +874,11 @@ public class ContainerShop implements Shop {
|
||||
// check price restriction
|
||||
PriceLimiter.CheckResult priceRestriction = plugin.getShopManager().getPriceLimiter().check(item, price);
|
||||
if (priceRestriction.getStatus() != PriceLimiter.Status.PASS) {
|
||||
if (price < priceRestriction.getMin()) {
|
||||
if (priceRestriction.getStatus() == PriceLimiter.Status.NOT_VALID) {
|
||||
setDirty();
|
||||
price = priceRestriction.getMin();
|
||||
this.update();
|
||||
} else if (price < priceRestriction.getMin()) {
|
||||
setDirty();
|
||||
price = priceRestriction.getMin();
|
||||
this.update();
|
||||
|
||||
@@ -887,6 +887,9 @@ public class ShopManager {
|
||||
String.valueOf(materialLimit.getKey()),
|
||||
String.valueOf(materialLimit.getValue())));
|
||||
return;
|
||||
case NOT_VALID:
|
||||
MsgUtil.sendMessage(p, MsgUtil.getMessage("not-a-number", p, message));
|
||||
return;
|
||||
}
|
||||
|
||||
// Set to 1 when disabled stacking shop
|
||||
|
||||
@@ -36,6 +36,9 @@ public class PriceLimiter {
|
||||
|
||||
@NotNull
|
||||
public CheckResult check(@NotNull ItemStack stack, double price) {
|
||||
if (Double.isInfinite(price) || Double.isNaN(price)) {
|
||||
return new CheckResult(Status.NOT_VALID, minPrice, maxPrice);
|
||||
}
|
||||
if (allowFreeShop) {
|
||||
if (price != 0 && price < minPrice) {
|
||||
return new CheckResult(Status.REACHED_PRICE_MIN_LIMIT, minPrice, maxPrice);
|
||||
@@ -77,6 +80,7 @@ public class PriceLimiter {
|
||||
PASS,
|
||||
REACHED_PRICE_MAX_LIMIT,
|
||||
REACHED_PRICE_MIN_LIMIT,
|
||||
PRICE_RESTRICTED
|
||||
PRICE_RESTRICTED,
|
||||
NOT_VALID
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user