From 640aed9a48e19e045eb42a9c87ad24cac38ca64e Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Thu, 3 Mar 2022 02:33:18 +0100 Subject: [PATCH] Added a way to manually overwrite points per item --- .../java/com/alttd/GUI/windows/BuyGUI.java | 2 +- .../java/com/alttd/GUI/windows/SellGUI.java | 2 +- .../java/com/alttd/config/WorthConfig.java | 3 ++- src/main/java/com/alttd/objects/Price.java | 21 ++++++++++++------- src/main/java/com/alttd/util/Utilities.java | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/alttd/GUI/windows/BuyGUI.java b/src/main/java/com/alttd/GUI/windows/BuyGUI.java index 1c3b5dd..42c10de 100644 --- a/src/main/java/com/alttd/GUI/windows/BuyGUI.java +++ b/src/main/java/com/alttd/GUI/windows/BuyGUI.java @@ -61,7 +61,7 @@ public class BuyGUI extends GUIMerchant { } private void buy(VillagerType villagerType, Player player, Material material, int amount, Price price) { - int itemPts = (int) (Math.floor(price.getPrice(1) / WorthConfig.POINT_MOD) + 1); + int itemPts = price.getPoints(); int transPts = itemPts * amount; EconUser econUser = EconUser.getUser(player.getUniqueId()); int oldPoints = econUser.getPointsMap().getOrDefault(villagerType.getName(), 0); diff --git a/src/main/java/com/alttd/GUI/windows/SellGUI.java b/src/main/java/com/alttd/GUI/windows/SellGUI.java index 9f4e2e2..9914d94 100644 --- a/src/main/java/com/alttd/GUI/windows/SellGUI.java +++ b/src/main/java/com/alttd/GUI/windows/SellGUI.java @@ -73,7 +73,7 @@ public class SellGUI extends GUIMerchant { EconUser econUser = EconUser.getUser(player.getUniqueId()); int oldPoints = econUser.getPointsMap().getOrDefault(villagerType.getName(), 0); - int itemPts = (int) (Math.floor(price.getPrice(1) / WorthConfig.POINT_MOD) + 1); + int itemPts = price.getPoints(); int transPts = (itemPts * amount) * -1; double cost = price.calculatePriceThing(oldPoints, transPts, false, itemPts); diff --git a/src/main/java/com/alttd/config/WorthConfig.java b/src/main/java/com/alttd/config/WorthConfig.java index 84b74f3..c329bbc 100644 --- a/src/main/java/com/alttd/config/WorthConfig.java +++ b/src/main/java/com/alttd/config/WorthConfig.java @@ -49,7 +49,8 @@ public class WorthConfig extends AbstractConfig { Logger.severe("Null key in worth.yml?"); continue; } - map.put(Material.getMaterial(key), new Price(Utilities.round(worth.getDouble(key), 2))); + Material material = Material.getMaterial(key); + map.put(material, new Price(Utilities.round(worth.getDouble(key), 2), material)); } } diff --git a/src/main/java/com/alttd/objects/Price.java b/src/main/java/com/alttd/objects/Price.java index 1dc3a57..dd1e2a8 100644 --- a/src/main/java/com/alttd/objects/Price.java +++ b/src/main/java/com/alttd/objects/Price.java @@ -2,22 +2,29 @@ package com.alttd.objects; import com.alttd.config.WorthConfig; import com.alttd.util.Utilities; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; public final class Price { private final double price; private final int points; - private static final double[] xMult = {Integer.MIN_VALUE, -6000, -4000, -2000, -500, 500, 2000, 4000, 6000, Integer.MAX_VALUE}; - private static final double[] yMultBuy = {0.5, 0.67, 0.8, 0.9, 1, 1.5, 2.5, 5, 10}; - private static final double[] yMultSell = {0.1, 0.2, 0.4, 0.67, 1, 1.1, 1.25, 1.5, 2}; + private static final double[] xMult = {Integer.MIN_VALUE, -10000, -6000, -4000, -2000, -500, 500, 2000, 4000, 6000, 10000, Integer.MAX_VALUE}; + private static final double[] yMultBuy = {0.5, 0.5, 0.67, 0.8, 0.9, 1, 1.5, 2.5, 5, 10, 100}; + private static final double[] yMultSell = {0.01, 0.1, 0.2, 0.4, 0.67, 1, 1.1, 1.25, 1.5, 2, 2}; - public Price(double price) { + public Price(double price, Material material) { this.price = price; - this.points = (int) (Math.floor(price / WorthConfig.POINT_MOD) + 1); + switch (material) { + case NETHER_STAR -> { + this.points = (int) (this.price / 2); + } + default -> this.points = (int) (Math.floor(price / WorthConfig.POINT_MOD) + 1); + } } - public static Price addPrice(Price one, Price two) { - return (new Price(Utilities.round(one.getPrice(1) + two.getPrice(1), 2))); + public static Price addPrice(Price one, Price two, Material material) { + return (new Price(Utilities.round(one.getPrice(1) + two.getPrice(1), 2), material)); } public static double getCurrentMultiplier(int points, boolean buy) { diff --git a/src/main/java/com/alttd/util/Utilities.java b/src/main/java/com/alttd/util/Utilities.java index 6f9b6f1..c060449 100644 --- a/src/main/java/com/alttd/util/Utilities.java +++ b/src/main/java/com/alttd/util/Utilities.java @@ -133,7 +133,7 @@ public class Utilities { if (price == null) price = tmp; else - price = Price.addPrice(price, tmp); + price = Price.addPrice(price, tmp, item.getType()); } return (price); }