From 3b2f71465f8ab2ba9546fa9f0c4e1e54d21427a5 Mon Sep 17 00:00:00 2001 From: Leonidius20 Date: Sat, 11 Aug 2018 16:13:04 +0300 Subject: [PATCH] Fixed price calculation for items with discounts --- src/main/java/ua/leonidius/trading/buy/Buy.java | 12 ++++++++---- src/main/resources/plugin.yml | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ua/leonidius/trading/buy/Buy.java b/src/main/java/ua/leonidius/trading/buy/Buy.java index c18e30c..46d4469 100644 --- a/src/main/java/ua/leonidius/trading/buy/Buy.java +++ b/src/main/java/ua/leonidius/trading/buy/Buy.java @@ -74,14 +74,18 @@ public static double getPrice (Item item) { int id = item.getId(); int meta = item.getDamage(); String key = "b-"+id+"-"+meta; + double priceWithoutDiscount = Main.buycfg.getDouble(key); - double priceWithDiscount = priceWithoutDiscount; + String discountKey = "d-"+id+"-"+meta; + if (Main.discountCfg.exists(discountKey)) { - double discountModifier = Main.discountCfg.getDouble(discountKey)/100; - priceWithDiscount = priceWithoutDiscount*discountModifier; + double discountPercent = Main.discountCfg.getDouble(discountKey); + double discount = (priceWithoutDiscount * discountPercent) / 100; + return priceWithoutDiscount - discount; } - return priceWithDiscount; + + return priceWithoutDiscount; } private static int getMaxByMoney(Player player, Item item){ diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6284d3f..542a35d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Trading Commands main: ua.leonidius.trading.Main -version: 1.0.2 +version: 1.0.3 author: Leonidius20 api: ["1.0.0"] description: Shop and auction system, based on commands.