11package eu .xap3y .xagui ;
22
3- import com .cryptomorin .xseries .XMaterial ;
43import eu .xap3y .xagui .interfaces .GuiButtonInterface ;
4+ import eu .xap3y .xagui .interfaces .GuiMenuInterface ;
55import eu .xap3y .xagui .listeners .MenuListener ;
66import eu .xap3y .xagui .models .GuiButton ;
77import lombok .Getter ;
1212import org .bukkit .plugin .java .JavaPlugin ;
1313import org .jetbrains .annotations .NotNull ;
1414
15+ import java .util .Map ;
16+ import java .util .UUID ;
17+ import java .util .concurrent .ConcurrentHashMap ;
18+
1519public class XaGui {
1620
1721 private final JavaPlugin plugin ;
1822
23+ private final static Map <UUID , GuiMenuInterface > openMenus = new ConcurrentHashMap <>();
24+
1925 public XaGui (@ NotNull JavaPlugin plugin ) {
2026 this .plugin = plugin ;
2127 plugin .getServer ().getPluginManager ().registerEvents (new MenuListener (plugin ), plugin );
@@ -46,6 +52,28 @@ public GuiMenu createMenu(String name, int rows, int pages) {
4652 return new GuiMenu (plugin , name , rows , pages );
4753 }
4854
55+ /**
56+ * Register an open menu
57+ *
58+ * @param uuid The UUID of the player
59+ */
60+ public void closeMenu (UUID uuid ) {
61+ if (openMenus .containsKey (uuid )) {
62+ GuiMenuInterface menu = openMenus .get (uuid );
63+ menu .close ();
64+ }
65+ openMenus .remove (uuid );
66+ }
67+
68+ /**
69+ * Close all open menus
70+ */
71+ public void closeAll () {
72+ for (UUID uuid : openMenus .keySet ()) {
73+ closeMenu (uuid );
74+ }
75+ }
76+
4977 /**
5078 * Set the item that will be used to fill the menu border
5179 *
@@ -55,6 +83,15 @@ public void setBorderItem(ItemStack item) {
5583 borderFiller = item ;
5684 }
5785
86+ /**
87+ * Get all open menus
88+ *
89+ * @return A map of all open menus
90+ */
91+ public Map <UUID , GuiMenuInterface > getOpenMenus () {
92+ return openMenus ;
93+ }
94+
5895 /**
5996 * Set the item that will be used as the close button
6097 *
@@ -100,26 +137,46 @@ public void setCloseButtonSound(Sound sound) {
100137 closeButtonSound = sound ;
101138 }
102139
140+ /**
141+ * Set the sound that will be played when a player clicks a button
142+ *
143+ * @param sound The sound that will be played
144+ */
145+ public void setButtonClickSound (Sound sound , float volume ) {
146+ buttonClickSoundVolume = volume ;
147+ buttonClickSound = sound ;
148+ }
149+
150+ /**
151+ * Set the sound that will be played when a player clicks a button
152+ *
153+ * @param sound The sound that will be played
154+ */
155+ public void setClickSound (Sound sound ) {
156+ clickSound = sound ;
157+ }
158+
103159 @ Getter
104160 private static Sound redirectSound = null ;
105161
162+ @ Getter
163+ private static Sound clickSound = null ;
164+
165+ @ Getter
166+ private static Sound buttonClickSound = null ;
167+
168+ @ Getter
169+ private static float buttonClickSoundVolume = 1f ;
170+
106171 @ Getter
107172 private static Sound closeButtonSound = null ;
108173
109174 @ Getter
110- private static ItemStack borderFiller = new GuiButton (
111- XMaterial .GRAY_STAINED_GLASS_PANE .parseItem () != null
112- ? XMaterial .GRAY_STAINED_GLASS_PANE .parseItem ()
113- : new ItemStack (Material .AIR )
114- ).setName ("&r" ).getItem ();
175+ private static ItemStack borderFiller = new GuiButton (Material .GRAY_STAINED_GLASS_PANE ).setName ("&r" ).getItem ();
115176
116177 @ Getter
117178 private static GuiButtonInterface closeButton = new GuiButton (
118- new ItemStack (
119- XMaterial .BARRIER .parseMaterial () != null
120- ? XMaterial .BARRIER .parseMaterial ()
121- : Material .AIR
122- )
179+ new ItemStack (Material .BARRIER )
123180 ).setName ("&cClose" ).withListener (e -> {
124181 e .getWhoClicked ().closeInventory ();
125182 if (closeButtonSound != null ) {
@@ -133,4 +190,12 @@ public void setCloseButtonSound(Sound sound) {
133190
134191 @ Getter
135192 private static ItemStack previousPageButton = new GuiButton (Material .ARROW ).setName ("&ePrevious page" ).getItem ();
193+
194+ public static void addOpenMenu (UUID uuid , GuiMenuInterface menu ) {
195+ openMenus .put (uuid , menu );
196+ }
197+
198+ public static void removeOpenMenu (UUID uuid ) {
199+ openMenus .remove (uuid );
200+ }
136201}
0 commit comments