33import eu .xap3y .xagui .adapter .Legacy ;
44import eu .xap3y .xagui .interfaces .GuiButtonInterface ;
55import eu .xap3y .xagui .interfaces .GuiMenuInterface ;
6+ import eu .xap3y .xagui .interfaces .listeners .GuiCloseInterface ;
7+ import eu .xap3y .xagui .interfaces .listeners .GuiOpenInterface ;
68import eu .xap3y .xagui .listeners .MenuListener ;
79import eu .xap3y .xagui .models .GuiButton ;
810import lombok .Getter ;
11+ import lombok .Setter ;
912import org .bukkit .Material ;
1013import org .bukkit .Sound ;
1114import org .bukkit .entity .Player ;
@@ -21,6 +24,8 @@ public class XaGui {
2124
2225 private final JavaPlugin plugin ;
2326
27+ private final String VERSION = "1.3.3" ;
28+
2429 @ Getter
2530 private static boolean isPaper = false ;
2631
@@ -34,7 +39,7 @@ public class XaGui {
3439
3540 public XaGui (@ NotNull JavaPlugin plugin ) {
3641 this .plugin = plugin ;
37- plugin .getServer ().getConsoleSender ().sendMessage ("Registering XaGui.." );
42+ plugin .getServer ().getConsoleSender ().sendMessage ("Registering XaGui v" + VERSION + " .." );
3843 plugin .getServer ().getPluginManager ().registerEvents (new MenuListener (plugin ), plugin );
3944
4045 try {
@@ -55,6 +60,8 @@ public XaGui(@NotNull JavaPlugin plugin) {
5560 Class .forName ("io.papermc.paper.threadedregions.RegionizedServer" );
5661 isFolia = true ;
5762 } catch (ClassNotFoundException ignored ) {}
63+
64+ plugin .getServer ().getConsoleSender ().sendMessage ("XaGui registered successfully!" );
5865 }
5966
6067 /**
@@ -113,6 +120,24 @@ public void setBorderItem(ItemStack item) {
113120 borderFiller = item ;
114121 }
115122
123+ /**
124+ * Set a handler invoked when any xagui inventory is closed.
125+ *
126+ * @param closeAction close handler
127+ */
128+ public void setOnClose (GuiCloseInterface closeAction ) {
129+ onCloseAction = closeAction ;
130+ }
131+
132+ /**
133+ * Set a handler invoked when any xagui inventory is opened.
134+ *
135+ * @param openAction open handler
136+ */
137+ public void setOnOpen (GuiOpenInterface openAction ) {
138+ this .onOpenAction = openAction ;
139+ }
140+
116141 /**
117142 * Get all open menus
118143 *
@@ -204,14 +229,28 @@ public void setClickSound(Sound sound) {
204229 @ Getter
205230 private static ItemStack borderFiller = Legacy .createBorderFiller ();
206231
232+ @ Getter
233+ private static GuiCloseInterface onCloseAction = null ;
234+
235+ @ Getter
236+ private static GuiOpenInterface onOpenAction = null ;
237+
207238 @ Getter
208239 private static GuiButtonInterface closeButton = new GuiButton (
209240 new ItemStack (Material .BARRIER )
210241 ).setName ("&cClose" ).withListener (e -> {
211242 e .getWhoClicked ().closeInventory ();
212243 if (closeButtonSound != null ) {
213244 Player p = (Player ) e .getWhoClicked ();
214- p .playSound (p , closeButtonSound != null ? closeButtonSound : Sound .BLOCK_ENDER_CHEST_CLOSE , .5f , 1f );
245+ try {
246+ p .playSound (p , closeButtonSound != null ? closeButtonSound : Sound .BLOCK_ENDER_CHEST_CLOSE , .5f , 1f );
247+ } catch (NoSuchFieldError | NoSuchMethodError | Exception ignored ) {
248+ try { // 1.8.8 fallback
249+ p .playSound (p .getLocation (), closeButtonSound != null ? closeButtonSound : Sound .BLOCK_ENDER_CHEST_CLOSE , .5f , 1f );
250+ } catch (NoSuchFieldError | NoSuchMethodError | Exception ignored2 ) {
251+ // IGNORE
252+ }
253+ }
215254 }
216255 });
217256
0 commit comments