From 965d93197800ef30c289d2d8df456336fad644b5 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Thu, 24 Jun 2021 19:40:58 +0100 Subject: [PATCH] Include prices in price restriction messages (Resolves #461) --- .../Modules/PriceRestrictionModule.java | 17 +++++++++++++---- .../PreShopCreation/ErrorMessageSender.java | 12 ------------ src/main/resources/languages/lang.en.yml | 8 ++++---- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java index 17a7389..957f648 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java @@ -3,6 +3,7 @@ package com.Acrobot.ChestShop.Listeners.Modules; import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.Breeze.Utils.QuantityUtil; import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Configuration.Messages; import com.Acrobot.ChestShop.Events.ChestShopReloadEvent; import com.Acrobot.ChestShop.Events.ItemParseEvent; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; @@ -124,24 +125,32 @@ public class PriceRestrictionModule implements Listener { if (PriceUtil.hasBuyPrice(event.getSignLine(PRICE_LINE))) { BigDecimal buyPrice = PriceUtil.getExactBuyPrice(event.getSignLine(PRICE_LINE)); - if (isValid("min.buy_price." + itemType) && buyPrice.compareTo(BigDecimal.valueOf(configuration.getDouble("min.buy_price." + itemType) * amount)) < 0) { + BigDecimal minBuyPrice = BigDecimal.valueOf(configuration.getDouble("min.buy_price." + itemType) * amount); + if (isValid("min.buy_price." + itemType) && buyPrice.compareTo(minBuyPrice) < 0) { event.setOutcome(BUY_PRICE_BELOW_MIN); + Messages.BUY_PRICE_ABOVE_MAX.sendWithPrefix(event.getPlayer(), "price", buyPrice.toPlainString(), "minprice", minBuyPrice.toPlainString()); } - if (isValid("max.buy_price." + itemType) && buyPrice.compareTo(BigDecimal.valueOf(configuration.getDouble("max.buy_price." + itemType) * amount)) > 0) { + BigDecimal maxBuyPrice = BigDecimal.valueOf(configuration.getDouble("max.buy_price." + itemType) * amount); + if (isValid("max.buy_price." + itemType) && buyPrice.compareTo(maxBuyPrice) > 0) { event.setOutcome(BUY_PRICE_ABOVE_MAX); + Messages.BUY_PRICE_ABOVE_MAX.sendWithPrefix(event.getPlayer(), "price", buyPrice.toPlainString(), "maxprice", maxBuyPrice.toPlainString()); } } if (PriceUtil.hasSellPrice(event.getSignLine(PRICE_LINE))) { BigDecimal sellPrice = PriceUtil.getExactSellPrice(event.getSignLine(PRICE_LINE)); - if (isValid("min.sell_price." + itemType) && sellPrice.compareTo(BigDecimal.valueOf(configuration.getDouble("min.sell_price." + itemType) * amount)) < 0) { + BigDecimal minSellPrice = BigDecimal.valueOf(configuration.getDouble("min.sell_price." + itemType) * amount); + if (isValid("min.sell_price." + itemType) && sellPrice.compareTo(minSellPrice) < 0) { event.setOutcome(SELL_PRICE_BELOW_MIN); + Messages.BUY_PRICE_ABOVE_MAX.sendWithPrefix(event.getPlayer(), "price", sellPrice.toPlainString(), "minprice", minSellPrice.toPlainString()); } - if (isValid("max.sell_price." + itemType) && sellPrice.compareTo(BigDecimal.valueOf(configuration.getDouble("max.sell_price." + itemType) * amount)) > 0) { + BigDecimal maxSellPrice = BigDecimal.valueOf(configuration.getDouble("max.sell_price." + itemType) * amount); + if (isValid("max.sell_price." + itemType) && sellPrice.compareTo(maxSellPrice) > 0) { event.setOutcome(SELL_PRICE_ABOVE_MAX); + Messages.BUY_PRICE_ABOVE_MAX.sendWithPrefix(event.getPlayer(), "price", sellPrice.toPlainString(), "maxprice", maxSellPrice.toPlainString()); } } } 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 e738ac6..39c2af2 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java @@ -35,18 +35,6 @@ public class ErrorMessageSender implements Listener { case SELL_PRICE_HIGHER_THAN_BUY_PRICE: message = Messages.YOU_CANNOT_CREATE_SHOP; break; - case SELL_PRICE_ABOVE_MAX: - message = Messages.SELL_PRICE_ABOVE_MAX; - break; - case SELL_PRICE_BELOW_MIN: - message = Messages.SELL_PRICE_BELOW_MIN; - break; - case BUY_PRICE_ABOVE_MAX: - message = Messages.BUY_PRICE_ABOVE_MAX; - break; - case BUY_PRICE_BELOW_MIN: - message = Messages.BUY_PRICE_BELOW_MIN; - break; case NO_CHEST: message = Messages.NO_CHEST_DETECTED; break; diff --git a/src/main/resources/languages/lang.en.yml b/src/main/resources/languages/lang.en.yml index d9f7de9..9c73fbd 100644 --- a/src/main/resources/languages/lang.en.yml +++ b/src/main/resources/languages/lang.en.yml @@ -64,10 +64,10 @@ INVALID_SHOP_PRICE: "The shop has an invalid price!" INVALID_SHOP_QUANTITY: "The shop has an invalid quantity!" CANNOT_ACCESS_THE_CHEST: "You don't have permissions to access this chest!" -SELL_PRICE_ABOVE_MAX: "Sell price is above maximum!" -SELL_PRICE_BELOW_MIN: "Sell price is below minimum!" -BUY_PRICE_ABOVE_MAX: "Buy price is above maximum!" -BUY_PRICE_BELOW_MIN: "Buy price is below minimum!" +SELL_PRICE_ABOVE_MAX: "Sell price %price is above maximum %maxprice!" +SELL_PRICE_BELOW_MIN: "Sell price %price is below minimum %minprice!" +BUY_PRICE_ABOVE_MAX: "Buy price %price is above maximum %maxprice!" +BUY_PRICE_BELOW_MIN: "Buy price %price is below minimum %minprice!" CLICK_TO_AUTOFILL_ITEM: "Click the sign with the item that this shop is for!" NO_ITEM_IN_HAND: "You don't have an item in your hand to autofill!"