Skip to content

Commit 2aad6e0

Browse files
committed
v1.3.3
1 parent ddbe775 commit 2aad6e0

5 files changed

Lines changed: 88 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ A simple GUI library for Minecraft plugins. This library is written in Kotlin an
88

99
For installation instructions and usage examples, visit:
1010

11-
## https://xagui.xap3y.space
11+
## https://xagui.xap3y.eu

pom.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
<groupId>eu.xap3y</groupId>
88
<artifactId>xagui</artifactId>
9-
<version>1.3.2</version>
9+
<version>1.3.3</version>
1010
<packaging>jar</packaging>
11-
<url>https://xagui.xap3y.space</url>
11+
<url>https://xagui.xap3y.eu</url>
1212
<name>XaGui</name>
1313

1414
<properties>
@@ -37,13 +37,13 @@
3737
</license>
3838
</licenses>
3939

40-
<description>LightWeight minecraft GUI library</description>
40+
<description>LightWeight Minecraft GUI library</description>
4141
<developers>
4242
<developer>
4343
<id>xap3y</id>
4444
<name>Martin</name>
4545
<email>xap3y@mail.ru</email>
46-
<url>https://xap3y.fun</url>
46+
<url>https://xap3y.eu</url>
4747
</developer>
4848
</developers>
4949

@@ -154,5 +154,11 @@
154154
<version>1.18.32</version>
155155
<scope>provided</scope>
156156
</dependency>
157+
<dependency>
158+
<groupId>com.github.cryptomorin</groupId>
159+
<artifactId>XSeries</artifactId>
160+
<version>13.6.0</version>
161+
<scope>provided</scope>
162+
</dependency>
157163
</dependencies>
158164
</project>

src/main/java/eu/xap3y/xagui/XaGui.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import eu.xap3y.xagui.adapter.Legacy;
44
import eu.xap3y.xagui.interfaces.GuiButtonInterface;
55
import eu.xap3y.xagui.interfaces.GuiMenuInterface;
6+
import eu.xap3y.xagui.interfaces.listeners.GuiCloseInterface;
7+
import eu.xap3y.xagui.interfaces.listeners.GuiOpenInterface;
68
import eu.xap3y.xagui.listeners.MenuListener;
79
import eu.xap3y.xagui.models.GuiButton;
810
import lombok.Getter;
11+
import lombok.Setter;
912
import org.bukkit.Material;
1013
import org.bukkit.Sound;
1114
import 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

src/main/java/eu/xap3y/xagui/listeners/MenuListener.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public void onInventoryClose(InventoryCloseEvent e) {
108108

109109
XaGui.removeOpenMenu(e.getPlayer().getUniqueId());
110110

111+
if (XaGui.getOnCloseAction() != null) {
112+
XaGui.getOnCloseAction().onClose(e);
113+
}
114+
111115
if (clickedInventory.onCloseAction != null) {
112116
clickedInventory.onCloseAction.onClose(e);
113117
}
@@ -124,7 +128,19 @@ public void onInventoryOpen(InventoryOpenEvent e) {
124128

125129
if (clickedInventory.getOpenSound() != null) {
126130
Player player = (Player) e.getPlayer();
127-
player.playSound(player, clickedInventory.getOpenSound(), clickedInventory.getOpenSoundVolume(), 1f);
131+
try {
132+
player.playSound(player, clickedInventory.getOpenSound(), clickedInventory.getOpenSoundVolume(), 1f);
133+
} catch (NoSuchFieldError | NoSuchMethodError | Exception ignored) {
134+
try { // 1.8.8 fallback
135+
player.playSound(player.getLocation(), clickedInventory.getOpenSound(), clickedInventory.getOpenSoundVolume(), 1f);
136+
} catch (NoSuchFieldError | NoSuchMethodError | Exception ignored2) {
137+
// IGNORE
138+
}
139+
}
140+
}
141+
142+
if (XaGui.getOnOpenAction() != null) {
143+
XaGui.getOnOpenAction().onOpen(e);
128144
}
129145

130146
if (clickedInventory.onOpenAction != null) {

src/main/java/eu/xap3y/xagui/models/GuiButton.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package eu.xap3y.xagui.models;
22

3+
import com.cryptomorin.xseries.XMaterial;
34
import eu.xap3y.xagui.XaGui;
45
import eu.xap3y.xagui.adapter.PaperAdapter;
56
import eu.xap3y.xagui.interfaces.GuiButtonInterface;
@@ -84,6 +85,15 @@ public GuiButton(Material material) {
8485
this(new ItemStack(material));
8586
}
8687

88+
/**
89+
* Create a new GuiButton with a XMaterial (amount 1).
90+
*
91+
* @param xmaterial the material to use
92+
*/
93+
public GuiButton(XMaterial xmaterial) {
94+
this(new ItemStack(xmaterial.get()));
95+
}
96+
8797
/**
8898
* Get the material type of this button's icon.
8999
*
@@ -473,7 +483,15 @@ public void callRedirect(Player p) {
473483
menu.open(p);
474484
}
475485
if (XaGui.getRedirectSound() != null) {
476-
p.playSound(p, XaGui.getRedirectSound(), 1f, 1f);
486+
try {
487+
p.playSound(p, XaGui.getRedirectSound(), 1f, 1f);
488+
} catch (Exception ignored) {
489+
try {
490+
p.playSound(p.getLocation(), XaGui.getRedirectSound(), 1f, 1f);
491+
} catch (Exception ignored2) {
492+
// IGNORE
493+
}
494+
}
477495
}
478496
}
479497
}

0 commit comments

Comments
 (0)