From 7c27fc0d54f1718188d7d0e07b1d44ace3e63f11 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 18 Aug 2016 15:33:58 +0200 Subject: [PATCH] Added configurable value "allow-decimals-in-price" When disabled, "auto-calculate-item-amount" will be disabled too, even if it's set to true in the config. This closes #20 --- src/main/java/de/epiceric/shopchest/ShopCommand.java | 9 ++++++++- src/main/java/de/epiceric/shopchest/config/Config.java | 6 +++++- .../de/epiceric/shopchest/language/LanguageUtils.java | 1 + .../de/epiceric/shopchest/language/LocalizedMessage.java | 1 + src/main/resources/config.yml | 3 +++ src/main/resources/lang/de_DE.lang | 3 ++- src/main/resources/lang/en_US.lang | 8 ++++++-- 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/ShopCommand.java b/src/main/java/de/epiceric/shopchest/ShopCommand.java index 1c27b88..7ee6d3f 100644 --- a/src/main/java/de/epiceric/shopchest/ShopCommand.java +++ b/src/main/java/de/epiceric/shopchest/ShopCommand.java @@ -264,7 +264,14 @@ class ShopCommand extends BukkitCommand { return; } - plugin.debug(p.getName() + " has entered the numbers correctly"); + plugin.debug(p.getName() + " has entered numbers as prices and amount"); + + if (!plugin.getShopChestConfig().allow_decimals_in_price && (buyPrice != (int) buyPrice || sellPrice != (int) sellPrice)) { + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.PRICES_CONTAIN_DECIMALS)); + return; + } + + plugin.debug(p.getName() + " has entered the numbers correctly (according to allow-decimals configuration)"); boolean buyEnabled = !(buyPrice <= 0), sellEnabled = !(sellPrice <= 0); diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index 07b3284..214a2f8 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -70,6 +70,9 @@ public class Config { **/ public List blacklist; + /** Whether prices may contain decimals **/ + public boolean allow_decimals_in_price; + /** Whether the buy price of a shop must be greater than or equal the sell price **/ public boolean buy_greater_or_equal_sell; @@ -281,8 +284,9 @@ public class Config { database_mysql_password = plugin.getConfig().getString("database.mysql.password"); database_type = Database.DatabaseType.valueOf(plugin.getConfig().getString("database.type")); minimum_prices = (plugin.getConfig().getConfigurationSection("minimum-prices") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("minimum-prices").getKeys(true); + allow_decimals_in_price = plugin.getConfig().getBoolean("allow-decimals-in-price"); allow_broken_items = plugin.getConfig().getBoolean("allow-broken-items"); - auto_calculate_item_amount = plugin.getConfig().getBoolean("auto-calculate-item-amount"); + auto_calculate_item_amount = (allow_decimals_in_price && plugin.getConfig().getBoolean("auto-calculate-item-amount")); shopLimits_group = (plugin.getConfig().getConfigurationSection("shop-limits.group") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.group").getKeys(true); shopLimits_player = (plugin.getConfig().getConfigurationSection("shop-limits.player") == null) ? new HashSet() : plugin.getConfig().getConfigurationSection("shop-limits.player").getKeys(true); blacklist = (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList() : plugin.getConfig().getStringList("blacklist"); diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index e03664f..f19fb9f 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -879,6 +879,7 @@ public class LanguageUtils { messages.add(new LocalizedMessage(LocalizedMessage.Message.OUT_OF_STOCK, langConfig.getString("message.out-of-stock", "&cShop out of stock."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.ERROR_OCCURRED, langConfig.getString("message.error-occurred", "&cAn error occurred: %ERROR%"), Regex.ERROR)); messages.add(new LocalizedMessage(LocalizedMessage.Message.AMOUNT_PRICE_NOT_NUMBER, langConfig.getString("message.amount-and-price-not-number", "&cAmount and price must be a number."))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.PRICES_CONTAIN_DECIMALS, langConfig.getString("message.prices-contain-decimals", "&cPrices must not contain decimals."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_ITEM_IN_HAND, langConfig.getString("message.no-item-in-hand", "&cNo item in hand"))); messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_CREATE, langConfig.getString("message.click-chest-to-create-shop", "&aClick a chest to create a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE, langConfig.getString("message.click-chest-to-remove-shop", "&aClick a shop-chest to remove the shop."))); diff --git a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java index 4bfee30..c14f0c9 100644 --- a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java +++ b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java @@ -76,6 +76,7 @@ public class LocalizedMessage { OUT_OF_STOCK, ERROR_OCCURRED, AMOUNT_PRICE_NOT_NUMBER, + PRICES_CONTAIN_DECIMALS, NO_ITEM_IN_HAND, CLICK_CHEST_CREATE, CLICK_CHEST_REMOVE, diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8bf986e..92018c4 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -41,6 +41,9 @@ two-line-hologram-lift: 0.25 # The price will be calculated correspondingly. (If it's not clear enough, please let me know) auto-calculate-item-amount: false +# Set whether prices may contain decimals (prices of existing shops will stay) +allow-decimals-in-price: true + # Set whether players should be allowed to sell/buy broken items allow-broken-items: false diff --git a/src/main/resources/lang/de_DE.lang b/src/main/resources/lang/de_DE.lang index 858c088..bfb14d2 100644 --- a/src/main/resources/lang/de_DE.lang +++ b/src/main/resources/lang/de_DE.lang @@ -31,7 +31,8 @@ message.not-enough-items=&cNicht genug Items. message.vendor-not-enough-money=&cVerkäufer hat nicht genug Geld. message.out-of-stock=&cShop ausverkauft. message.error-occurred=&cEin Fehler ist aufgetreten: %ERROR% -message.amount-and-price-not-number=&cAnzahl und Preis müssen Zahlen sein. +message.amount-and-price-not-number=&cAnzahl und Preise müssen Zahlen sein. +message.prices-contain-decimals=&cPreise dürfen keine Dezimalen enthalten. message.no-item-in-hand=&cKein Item in der Hand. message.click-chest-to-create-shop=&aKlicke auf eine Truhe, um einen Shop zu erstellen. message.click-chest-to-remove-shop=&aKlicke auf einen Shop, um ihn zu entfernen. diff --git a/src/main/resources/lang/en_US.lang b/src/main/resources/lang/en_US.lang index 3233c4c..3aef3d0 100644 --- a/src/main/resources/lang/en_US.lang +++ b/src/main/resources/lang/en_US.lang @@ -115,8 +115,12 @@ message.out-of-stock=&cShop out of stock. # Usable regex: %ERROR% message.error-occurred=&cAn error occurred: %ERROR% -# Set the message when the arguments and of '/shop create' are not a number. -message.amount-and-price-not-number=&cAmount and price must be a number. +# Set the message when the arguments , and/or of '/shop create' are not a number. +message.amount-and-price-not-number=&cAmount and prices must be numbers. + +# Set the message when the config value "allow-decimals-in-prices" is set to false +# and a player enters a price with decimals +message.prices-contain-decimals=&cPrices must not contain decimals. # Set the message when the player doesn't hold an item in the hand. message.no-item-in-hand=&cNo item in hand