From c8d05906145173a34f97efb6f7200b84191d9c72 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Thu, 17 Jan 2019 18:08:54 +0100 Subject: [PATCH] Add different error messages when price limits are exceeded (#193) --- .../Acrobot/ChestShop/Configuration/Messages.java | 6 ++++++ .../ChestShop/Events/PreShopCreationEvent.java | 4 ++++ .../Listeners/Modules/PriceRestrictionModule.java | 15 ++++++++------- .../PreShopCreation/ErrorMessageSender.java | 12 ++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java index 2b5b11b..98d1d34 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java @@ -50,6 +50,12 @@ public class Messages { public static String INVALID_SHOP_DETECTED = "The shop cannot be used!"; public static String CANNOT_ACCESS_THE_CHEST = "You don't have permissions to access this chest!"; + @PrecededBySpace + public static String SELL_PRICE_ABOVE_MAX = "Sell price is above maximum!"; + public static String SELL_PRICE_BELOW_MIN ="Buy price is below minimum!"; + public static String BUY_PRICE_ABOVE_MAX = "Buy price is above maximum!"; + public static String BUY_PRICE_BELOW_MIN ="Buy price is below minimum!"; + @PrecededBySpace public static String CLICK_TO_AUTOFILL_ITEM = "Click the sign with the item that this shop is for!"; public static String NO_ITEM_IN_HAND = "You don't have an item in your hand to autofill!"; diff --git a/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java index 607cf81..84d83f2 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/PreShopCreationEvent.java @@ -159,6 +159,10 @@ public class PreShopCreationEvent extends Event implements Cancellable { UNKNOWN_PLAYER, SELL_PRICE_HIGHER_THAN_BUY_PRICE, + SELL_PRICE_ABOVE_MAX, + SELL_PRICE_BELOW_MIN, + BUY_PRICE_ABOVE_MAX, + BUY_PRICE_BELOW_MIN, NO_CHEST, 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 913dc3e..e7f4a8e 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Modules/PriceRestrictionModule.java @@ -1,11 +1,9 @@ package com.Acrobot.ChestShop.Listeners.Modules; import com.Acrobot.Breeze.Utils.MaterialUtil; -import com.Acrobot.Breeze.Utils.NumberUtil; import com.Acrobot.Breeze.Utils.PriceUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -17,7 +15,10 @@ import java.io.File; import java.io.IOException; import java.util.logging.Level; -import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.INVALID_PRICE; +import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.BUY_PRICE_ABOVE_MAX; +import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.BUY_PRICE_BELOW_MIN; +import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SELL_PRICE_ABOVE_MAX; +import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.SELL_PRICE_BELOW_MIN; import static com.Acrobot.ChestShop.Signs.ChestShopSign.ITEM_LINE; import static com.Acrobot.ChestShop.Signs.ChestShopSign.PRICE_LINE; @@ -102,11 +103,11 @@ public class PriceRestrictionModule implements Listener { double buyPrice = PriceUtil.getBuyPrice(event.getSignLine(PRICE_LINE)); if (isValid("min.buy_price." + itemType) && buyPrice < (configuration.getDouble("min.buy_price." + itemType) / amount)) { - event.setOutcome(INVALID_PRICE); + event.setOutcome(BUY_PRICE_BELOW_MIN); } if (isValid("max.buy_price." + itemType) && buyPrice > (configuration.getDouble("max.buy_price." + itemType) / amount)) { - event.setOutcome(INVALID_PRICE); + event.setOutcome(BUY_PRICE_ABOVE_MAX); } } @@ -114,11 +115,11 @@ public class PriceRestrictionModule implements Listener { double sellPrice = PriceUtil.getSellPrice(event.getSignLine(PRICE_LINE)); if (isValid("min.sell_price." + itemType) && sellPrice < (configuration.getDouble("min.sell_price." + itemType) / amount)) { - event.setOutcome(INVALID_PRICE); + event.setOutcome(SELL_PRICE_BELOW_MIN); } if (isValid("max.sell_price." + itemType) && sellPrice > (configuration.getDouble("max.sell_price." + itemType) / amount)) { - event.setOutcome(INVALID_PRICE); + event.setOutcome(SELL_PRICE_ABOVE_MAX); } } } 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..b34d7c5 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ErrorMessageSender.java @@ -32,6 +32,18 @@ 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;