11package com .sinam7 .dynamicshop .gui ;
22
3+ import com .sinam7 .dynamicshop .shop .ItemEntry ;
34import com .sinam7 .dynamicshop .shop .Shop ;
45import com .sinam7 .dynamicshop .shop .ShopManager ;
6+ import lombok .Getter ;
57import net .kyori .adventure .text .Component ;
68import net .kyori .adventure .text .format .Style ;
79import net .kyori .adventure .text .format .TextColor ;
1315import org .bukkit .inventory .ItemStack ;
1416import org .bukkit .inventory .meta .ItemMeta ;
1517
18+ import java .util .ArrayList ;
19+ import java .util .List ;
1620import java .util .Map ;
1721import java .util .stream .IntStream ;
1822
1923public class GuiManager {
2024
2125 private static ItemStack separator ;
26+ private static ItemStack nullshopicon ;
27+ private static ItemStack changePriceIcon ;
28+ private static ItemStack reloadIcon ;
2229
23- public static void createGui (Player player , Long shopId ) {
30+ private static final Style shopNameStyle = Style .style (TextColor .fromHexString ("#00ff00" ), TextDecoration .ITALIC .withState (false ));
31+ private static final Style shopLoreStyle = Style .style (TextColor .fromHexString ("#ffff00" ), TextDecoration .ITALIC .withState (false ));
32+ private static final Style noEntryStyle = Style .style (TextColor .fromHexString ("#ff0000" ), TextDecoration .ITALIC .withState (false ));
33+ private static final Style separatorStyle = Style .style (TextColor .fromHexString ("#ffffff" ), TextDecoration .BOLD , TextDecoration .ITALIC .withState (false ));
34+
35+ @ Getter
36+ private static final int changePriceIconLoc = 52 ;
37+ @ Getter
38+ private static final int reloadConfigIconLoc = 53 ;
39+
40+
41+ public static void createShopGui (Player player , Long shopId ) {
2442 Shop shop = ShopManager .getShop (shopId );
2543
2644 Inventory inv = Bukkit .createInventory (new GuiHolder (shopId ), 54 , Component .text (shop .getName () + ":" + shopId ));
@@ -34,16 +52,76 @@ public static void createGui(Player player, Long shopId) {
3452 player .openInventory (inv );
3553 }
3654
55+ public static void createAdminGui (Player player ) {
56+ Inventory inv = Bukkit .createInventory (new GuiHolder (-1 ), 54 , Component .text ("Admin GUI" ));
57+ for (Long shopId : ShopManager .shopList .keySet ()) {
58+ ItemStack shopIcon = getShopIcon (shopId );
59+ inv .setItem (Math .toIntExact (shopId ), shopIcon );
60+ }
61+
62+ inv .setItem (changePriceIconLoc , getChangePriceIcon ());
63+ inv .setItem (reloadConfigIconLoc , getReloadIcon ());
64+ player .openInventory (inv );
65+ }
66+
3767 private static ItemStack getSeparator () {
3868 if (separator == null ) {
39- ItemStack sep = new ItemStack (Material .WHITE_STAINED_GLASS_PANE );
40- ItemMeta itemMeta = sep .getItemMeta ();
41- itemMeta .displayName (Component .text ("====================" , Style . style ( TextColor . color ( 255 , 255 , 255 ), TextDecoration . BOLD ) ));
42- sep .setItemMeta (itemMeta );
43- separator = sep ;
69+ ItemStack ico = new ItemStack (Material .WHITE_STAINED_GLASS_PANE );
70+ ItemMeta itemMeta = ico .getItemMeta ();
71+ itemMeta .displayName (Component .text ("====================" , separatorStyle ));
72+ ico .setItemMeta (itemMeta );
73+ separator = ico ;
4474 }
4575 return separator ;
4676 }
4777
78+ private static ItemStack getShopIcon (Long shopId ) {
79+ Shop shop = ShopManager .getShop (shopId );
80+ ItemEntry entry = shop .getEntry (0 );
81+ if (entry == null ) {
82+ if (nullshopicon == null ) {
83+ ItemStack ico = new ItemStack (Material .BARRIER );
84+ ItemMeta itemMeta = ico .getItemMeta ();
85+
86+ itemMeta .displayName (Component .text ("%s:%s" .formatted (shop .getName (), shopId ), shopNameStyle ));
87+ itemMeta .lore (new ArrayList <>(List .of (Component .text ("No Entry" , noEntryStyle ))));
88+ ico .setItemMeta (itemMeta );
89+ nullshopicon = ico ;
90+ }
91+ return nullshopicon ;
92+ }
93+
94+ ItemStack icon ;
95+ icon = entry .getStock ().clone ();
96+ ItemMeta itemMeta = icon .getItemMeta ();
97+ itemMeta .displayName (Component .text ("%s:%s" .formatted (shop .getName (), shopId ), shopNameStyle ));
98+ int size = shop .getItemEntryMap ().size ();
99+ itemMeta .lore (new ArrayList <>(List .of (Component .text ((size + (size == 1 ? " entry" : " entries" )), shopLoreStyle ))));
100+ icon .setItemMeta (itemMeta );
101+ return icon ;
102+ }
103+
104+ private static ItemStack getChangePriceIcon () {
105+ if (changePriceIcon == null ) {
106+ ItemStack ico = new ItemStack (Material .GOLD_INGOT );
107+ ItemMeta itemMeta = ico .getItemMeta ();
108+ itemMeta .displayName (Component .text ("Change All Item's Price" , shopLoreStyle .decorate (TextDecoration .BOLD )));
109+ ico .setItemMeta (itemMeta );
110+ changePriceIcon = ico ;
111+ }
112+ return changePriceIcon ;
113+ }
114+
115+ private static ItemStack getReloadIcon () {
116+ if (reloadIcon == null ) {
117+ ItemStack ico = new ItemStack (Material .WRITTEN_BOOK );
118+ ItemMeta itemMeta = ico .getItemMeta ();
119+ itemMeta .displayName (Component .text ("Reload Config" , noEntryStyle .decorate (TextDecoration .BOLD )));
120+ ico .setItemMeta (itemMeta );
121+ reloadIcon = ico ;
122+ }
123+ return reloadIcon ;
124+ }
125+
48126
49127}
0 commit comments