11package net .earthmc .emcapi .sse .listeners ;
22
3+ import com .ghostchu .quickshop .api .event .economy .ShopSuccessPurchaseEvent ;
4+ import com .ghostchu .quickshop .api .obj .QUser ;
5+ import com .ghostchu .quickshop .api .shop .Shop ;
36import com .google .gson .JsonObject ;
47import com .palmergames .bukkit .towny .TownyAPI ;
58import com .palmergames .bukkit .towny .object .Resident ;
69import net .earthmc .emcapi .sse .SSEManager ;
710import net .earthmc .emcapi .util .EndpointUtils ;
811import org .bukkit .event .EventHandler ;
912import org .bukkit .event .EventPriority ;
10- import org .maxgamer .quickshop .api .event .ShopSuccessPurchaseEvent ;
11- import org .maxgamer .quickshop .api .shop .Shop ;
1213
1314import java .util .UUID ;
1415
@@ -21,7 +22,10 @@ public ShopSSEListener(SSEManager sseManager) {
2122 @ EventHandler (priority = EventPriority .MONITOR , ignoreCancelled = true )
2223 public void onShopPurchase (ShopSuccessPurchaseEvent event ) {
2324 Shop shop = event .getShop ();
24- UUID owner = shop .getOwner ();
25+ UUID owner = shop .getOwner ().getUniqueId ();
26+ if (owner == null ) {
27+ return ;
28+ }
2529
2630 boolean isSelling = shop .isSelling ();
2731 String purchaser = getPlayerName (event .getPurchaser ());
@@ -55,15 +59,23 @@ private void checkShopOut(Shop shop) {
5559 JsonObject alertMessage = new JsonObject ();
5660 alertMessage .addProperty ("action" , isSelling ? "out_of_stock" : "out_of_space" );
5761 alertMessage .add ("shop" , EndpointUtils .getShopObject (shop ));
58- sse .sendEvent ("ShopOutOf" + (isSelling ? "Stock " : "Space" ), alertMessage , shop .getOwner ());
62+ sse .sendEvent ("ShopOutOf" + (isSelling ? "Stock " : "Space" ), alertMessage , shop .getOwner (). getUniqueId () );
5963 }
6064
61- private String getPlayerName (UUID uuid ) {
65+ private String getPlayerName (QUser user ) {
66+ String name = user .getUsername ();
67+ if (name != null ) {
68+ return name ;
69+ }
70+ UUID uuid = user .getUniqueId ();
71+ if (uuid == null ) {
72+ return "Unknown player" ;
73+ }
6274 Resident res = TownyAPI .getInstance ().getResident (uuid );
6375 if (res != null ) {
6476 return res .getName ();
6577 } else {
66- return "Unknown player ` (" + uuid + ")` " ;
78+ return "Unknown player (" + uuid + ")" ;
6779 }
6880 }
6981}
0 commit comments