Skip to content

Commit ddbe775

Browse files
committed
v1.3.2
1 parent d147f1c commit ddbe775

6 files changed

Lines changed: 59 additions & 10 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class GuiMenu implements InventoryHolder, GuiMenuInterface {
6767
private ItemStack nextPageButton = null;
6868
private ItemStack previousPageButton = null;
6969
private Sound pageSwitchSound = null;
70+
private Sound openSound = null;
71+
private float openSoundFloat = 1f;
7072

7173
/** Callback invoked on inventory close. */
7274
public GuiCloseInterface onCloseAction = null;
@@ -891,6 +893,38 @@ public void setPageSwitchSound(Sound sound) {
891893
this.pageSwitchSound = sound;
892894
}
893895

896+
/**
897+
* Set an optional sound to play when opening the GUI.
898+
*
899+
* @param sound open sound (nullable to disable)
900+
* @param volume sound volume
901+
*/
902+
@Override
903+
public void setOpenSound(Sound sound, float volume) {
904+
this.openSound = sound;
905+
this.openSoundFloat = volume;
906+
}
907+
908+
/**
909+
* Get the sound played when opening the GUI.
910+
*
911+
* @return open sound
912+
*/
913+
@Override
914+
public Sound getOpenSound() {
915+
return openSound;
916+
}
917+
918+
/**
919+
* Get the volume of the sound played when opening the GUI.
920+
*
921+
* @return open sound volume
922+
*/
923+
@Override
924+
public float getOpenSoundVolume() {
925+
return openSoundFloat;
926+
}
927+
894928
// Borders
895929

896930
/**

src/main/java/eu/xap3y/xagui/adapter/ParseUtil.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public static Component parseText(String input) {
6161
// 1. Normalize section sign to ampersands
6262
String normalized = input.replace('§', '&');
6363

64-
// 2. Convert nibble hex (&x&F&F&0&0&0&A) -> <#FF000A>
64+
// 2. Convert nibble hex (&x&F&F&0&0&0&A) -> <reset><#FF000A>
6565
normalized = convertNibbleHex(normalized);
6666

67-
// 3. Convert hash hex (&#FF00AA) -> <#FF00AA>
67+
// 3. Convert hash hex (&#FF00AA) -> <reset><#FF00AA>
6868
normalized = convertHashHex(normalized);
6969

7070
// 4. Convert legacy color and format codes to MiniMessage tags
@@ -81,7 +81,7 @@ public static Component parseText(String input) {
8181
try {
8282
component = MINI.deserialize(normalized);
8383
} catch (Exception ex) {
84-
// Fallback: do pure legacy parse on the original normalized (before conversions could be stored separately if desired)
84+
// Fallback: do pure legacy parse
8585
component = LegacyComponentSerializer.legacyAmpersand().deserialize(input.replace('§', '&'));
8686
}
8787
} else {
@@ -99,13 +99,14 @@ private static String convertHashHex(String s) {
9999
StringBuffer sb = new StringBuffer();
100100
while (m.find()) {
101101
String hex = m.group(1).toUpperCase();
102-
m.appendReplacement(sb, "<#" + hex + ">");
102+
// Color codes in legacy reset formatting; ensure we reset before applying color
103+
m.appendReplacement(sb, "<reset><#" + hex + ">");
103104
}
104105
m.appendTail(sb);
105106
return sb.toString();
106107
}
107108

108-
// Convert &x&R&R&G&G&B&B sequences to <#RRGGBB>
109+
// Convert &x&R&R&G&G&B&B sequences to <reset><#RRGGBB>
109110
private static String convertNibbleHex(String s) {
110111
StringBuilder out = new StringBuilder(s.length());
111112
int i = 0;
@@ -120,7 +121,7 @@ && isNibbleSequence(s, i)) {
120121
for (int off = 3; off <= 13; off += 2) {
121122
hex.append(s.charAt(i + off));
122123
}
123-
out.append("<#").append(hex.toString().toUpperCase()).append(">");
124+
out.append("<reset><#").append(hex.toString().toUpperCase()).append(">");
124125
i += 14;
125126
} else {
126127
out.append(s.charAt(i));
@@ -157,17 +158,17 @@ private static String convertLegacyCodesToTags(String s) {
157158
if (c == '&' && i + 1 < s.length()) {
158159
char code = Character.toLowerCase(s.charAt(i + 1));
159160

160-
// Formatting
161+
// Formatting codes (&l, &o, &n, &m, &k, &r)
161162
if (FORMAT_TAGS.containsKey(code)) {
162163
String tag = FORMAT_TAGS.get(code);
163164
out.append('<').append(tag).append('>');
164165
i++;
165166
continue;
166167
}
167-
// Color
168+
// Color codes (&0..&f) should reset previous formatting
168169
if (COLOR_TAGS.containsKey(code)) {
169170
String tag = COLOR_TAGS.get(code);
170-
out.append('<').append(tag).append('>');
171+
out.append("<reset>").append('<').append(tag).append('>');
171172
i++;
172173
continue;
173174
}

src/main/java/eu/xap3y/xagui/interfaces/GuiButtonInterface.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public interface GuiButtonInterface {
5050

5151
GuiButton withRedirect(Supplier<GuiMenuInterface> menu);
5252
GuiButton withClickSound(Sound sound, float volume);
53+
default GuiButton withClickSound(Sound sound) {
54+
return withClickSound(sound, 1.0f);
55+
}
5356

5457
void callRedirect(Player p);
5558
}

src/main/java/eu/xap3y/xagui/interfaces/GuiMenuInterface.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public interface GuiMenuInterface {
9191
void setNextPageButton(ItemStack item);
9292
void setPreviousPageButton(ItemStack item);
9393
void setPageSwitchSound(Sound sound);
94+
void setOpenSound(Sound sound, float volume);
95+
default void setOpenSound(Sound sound) {
96+
setOpenSound(sound, 1.0f);
97+
}
98+
Sound getOpenSound();
99+
float getOpenSoundVolume();
94100

95101
void fillBorder();
96102
void fillBorder(int page, ItemStack item);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public void onInventoryOpen(InventoryOpenEvent e) {
122122

123123
XaGui.addOpenMenu(e.getPlayer().getUniqueId(), clickedInventory);
124124

125+
if (clickedInventory.getOpenSound() != null) {
126+
Player player = (Player) e.getPlayer();
127+
player.playSound(player, clickedInventory.getOpenSound(), clickedInventory.getOpenSoundVolume(), 1f);
128+
}
129+
125130
if (clickedInventory.onOpenAction != null) {
126131
clickedInventory.onOpenAction.onOpen(e);
127132
}

0 commit comments

Comments
 (0)