|
1 | 1 | package net.earthmc.emcapi.sse.listeners; |
2 | 2 |
|
| 3 | +import com.ghostchu.quickshop.api.event.Phase; |
3 | 4 | import com.ghostchu.quickshop.api.event.economy.ShopSuccessPurchaseEvent; |
| 5 | +import com.ghostchu.quickshop.api.event.management.ShopCreateEvent; |
| 6 | +import com.ghostchu.quickshop.api.event.management.ShopDeleteEvent; |
4 | 7 | import com.ghostchu.quickshop.api.obj.QUser; |
5 | 8 | import com.ghostchu.quickshop.api.shop.Shop; |
6 | 9 | import com.google.gson.JsonObject; |
@@ -44,6 +47,44 @@ public void onShopPurchase(ShopSuccessPurchaseEvent event) { |
44 | 47 | checkShopOut(shop); |
45 | 48 | } |
46 | 49 |
|
| 50 | + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |
| 51 | + public void onShopCreate(ShopCreateEvent event) { |
| 52 | + |
| 53 | + if (!event.isPhase(Phase.POST)) { |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + Shop shop = event.shop().orElse(null); |
| 58 | + if (shop == null) { |
| 59 | + return; |
| 60 | + } |
| 61 | + UUID owner = shop.getOwner().getUniqueId(); |
| 62 | + if (owner == null ) { |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + JsonObject message = new JsonObject(); |
| 67 | + message.add("shop", EndpointUtils.getShopObject(shop)); |
| 68 | + sse.sendEvent("ShopCreated", message, owner); |
| 69 | + } |
| 70 | + |
| 71 | + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) |
| 72 | + public void onShopDelete(ShopDeleteEvent event) { |
| 73 | + Shop shop = event.shop().orElse(null); |
| 74 | + if (shop == null) { |
| 75 | + return; |
| 76 | + } |
| 77 | + if (!event.isPhase(Phase.POST)) { |
| 78 | + return; |
| 79 | + } |
| 80 | + UUID owner = shop.getOwner().getUniqueId(); |
| 81 | + if (owner == null) return; |
| 82 | + |
| 83 | + JsonObject message = new JsonObject(); |
| 84 | + message.add("shop", EndpointUtils.getShopObject(shop)); |
| 85 | + sse.sendEvent("ShopDeleted", message, owner); |
| 86 | + } |
| 87 | + |
47 | 88 | private void checkOwnerBalance(UUID owner) { |
48 | 89 | Resident res = TownyAPI.getInstance().getResident(owner); |
49 | 90 | if (res == null || res.getAccount().getHoldingBalance() > 0) return; |
|
0 commit comments