From 6893d7bac77c4ff24c856eddd9651c704b779bd1 Mon Sep 17 00:00:00 2001 From: stjn Date: Wed, 10 Nov 2021 20:08:16 +0100 Subject: [PATCH] Added points to buy and sell events --- src/main/java/com/alttd/GUI/windows/BuyGUI.java | 8 +++++--- src/main/java/com/alttd/GUI/windows/SellGUI.java | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/alttd/GUI/windows/BuyGUI.java b/src/main/java/com/alttd/GUI/windows/BuyGUI.java index c3f2af8..f11e8d1 100644 --- a/src/main/java/com/alttd/GUI/windows/BuyGUI.java +++ b/src/main/java/com/alttd/GUI/windows/BuyGUI.java @@ -47,9 +47,11 @@ public class BuyGUI extends GUIMerchant { Template.of("price", String.valueOf(price)))); return; } + EconUser econUser = EconUser.users.get(player.getUniqueId()); + int oldPoints = econUser.getPointsMap().get(villagerType.getName()); + econ.withdrawPlayer(player, cost); - EconUser.users.get(player.getUniqueId()) - .addPoints(villagerType.getName(), price.getPoints()); + econUser.addPoints(villagerType.getName(), price.getPoints()); player.sendMessage(MiniMessage.get().parse(Config.PURCHASED_ITEM, Template.of("amount", String.valueOf(amount)), Template.of("item", material.toString()), @@ -57,7 +59,7 @@ public class BuyGUI extends GUIMerchant { Bukkit.getServer().getPluginManager() .callEvent(new SpawnShopEvent(player, amount, cost, material, - 0, 0, true)); + oldPoints, econUser.getPointsMap().get(villagerType.getName()), true)); } private ItemStack getPriceItem(double price) { diff --git a/src/main/java/com/alttd/GUI/windows/SellGUI.java b/src/main/java/com/alttd/GUI/windows/SellGUI.java index 1a4d670..7255ecc 100644 --- a/src/main/java/com/alttd/GUI/windows/SellGUI.java +++ b/src/main/java/com/alttd/GUI/windows/SellGUI.java @@ -40,10 +40,11 @@ public class SellGUI extends GUIMerchant { private void sell(VillagerType villagerType, Player player, Material material, int amount, Price price) { Economy econ = VillagerUI.getEcon(); double cost = price.getPrice(amount); + EconUser econUser = EconUser.users.get(player.getUniqueId()); + int oldPoints = econUser.getPointsMap().get(villagerType.getName()); econ.depositPlayer(player, cost); - EconUser.users.get(player.getUniqueId()) - .addPoints(villagerType.getName(), -price.getPoints()); + econUser.addPoints(villagerType.getName(), -price.getPoints()); player.sendMessage(MiniMessage.get().parse(Config.PURCHASED_ITEM, Template.of("amount", String.valueOf(amount)), Template.of("item", material.toString()), @@ -51,7 +52,7 @@ public class SellGUI extends GUIMerchant { Bukkit.getServer().getPluginManager() .callEvent(new SpawnShopEvent(player, amount, cost, material, - 0, 0, false)); + oldPoints, econUser.getPointsMap().get(villagerType.getName()), false)); } private ItemStack getPriceItem(double price) {