Skip to content

Commit

Permalink
Make EconomyShopGUI hook compatible with BUY and SELL task types
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSzabo committed Aug 7, 2024
1 parent 3fd3e07 commit 2c73ef4
Showing 1 changed file with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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));
}
}
}
}
}

0 comments on commit 2c73ef4

Please sign in to comment.