From 2c73ef496684f7d452a7b81fd0b37c0fabc2588c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Szab=C3=B3?= Date: Wed, 7 Aug 2024 14:04:22 +0200 Subject: [PATCH] Make EconomyShopGUI hook compatible with BUY and SELL task types --- .../EconomyShopGUIListener.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/gg/auroramc/quests/hooks/economyshopgui/EconomyShopGUIListener.java b/src/main/java/gg/auroramc/quests/hooks/economyshopgui/EconomyShopGUIListener.java index 5495765..6b51cb8 100644 --- a/src/main/java/gg/auroramc/quests/hooks/economyshopgui/EconomyShopGUIListener.java +++ b/src/main/java/gg/auroramc/quests/hooks/economyshopgui/EconomyShopGUIListener.java @@ -1,5 +1,6 @@ package gg.auroramc.quests.hooks.economyshopgui; +import gg.auroramc.aurora.api.AuroraAPI; import gg.auroramc.quests.AuroraQuests; import gg.auroramc.quests.api.quest.TaskType; import me.gypopo.economyshopgui.api.events.PostTransactionEvent; @@ -8,6 +9,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import java.util.Map; import java.util.Set; public class EconomyShopGUIListener implements Listener { @@ -25,18 +27,52 @@ public class EconomyShopGUIListener implements Listener { Transaction.Type.SHOPSTAND_SELL_SCREEN ); + @EventHandler(priority = EventPriority.MONITOR) public void onTransaction(PostTransactionEvent e) { if (!successResults.contains(e.getTransactionResult())) { return; } + var manager = AuroraQuests.getInstance().getQuestManager(); var price = e.getPrice(); if (sellTypes.contains(e.getTransactionType())) { - AuroraQuests.getInstance().getQuestManager().progress(e.getPlayer(), TaskType.SELL_WORTH, price, null); + manager.progress(e.getPlayer(), TaskType.SELL_WORTH, price, null); + } else if (buyTypes.contains(e.getTransactionType())) { + manager.progress(e.getPlayer(), TaskType.BUY_WORTH, price, null); + } + + if (sellTypes.contains(e.getTransactionType()) && !e.getItems().isEmpty()) { + for (var entry : e.getItems().entrySet()) { + var item = entry.getKey().getItemToGive(); + var amount = entry.getValue(); + + if (item != null) { + var id = AuroraAPI.getItemManager().resolveId(item); + if (id != null) { + manager.progress(e.getPlayer(), TaskType.SELL, amount, Map.of("type", id)); + } + } + } + } else if (sellTypes.contains(e.getTransactionType())) { + var item = e.getShopItem().getItemToGive(); + var amount = e.getAmount(); + if (item != null) { + var id = AuroraAPI.getItemManager().resolveId(item); + if (id != null) { + manager.progress(e.getPlayer(), TaskType.SELL, amount, Map.of("type", id)); + } + } } else if (buyTypes.contains(e.getTransactionType())) { - AuroraQuests.getInstance().getQuestManager().progress(e.getPlayer(), TaskType.BUY_WORTH, price, null); + var item = e.getShopItem().getItemToGive(); + var amount = e.getAmount(); + if (item != null) { + var id = AuroraAPI.getItemManager().resolveId(item); + if (id != null) { + manager.progress(e.getPlayer(), TaskType.BUY, amount, Map.of("type", id)); + } + } } } }