Skip to content

Commit

Permalink
Fix sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi committed Jan 6, 2025
1 parent 6af1de8 commit 1220761
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.eternalcode.multification.bukkit.notice.resolver.sound;

import java.lang.reflect.Method;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;

public final class SoundAccessor {

private static final Method VALUE_OF_METHOD;
private static final Method nameMethod;
private static final Method keyMethod;

static {
try {
Expand All @@ -15,6 +17,9 @@ public final class SoundAccessor {

nameMethod = Sound.class.getMethod("name");
nameMethod.setAccessible(true);

keyMethod = Sound.class.getMethod("getKey");
keyMethod.setAccessible(true);
}
catch (NoSuchMethodException noSuchMethodException) {
throw new RuntimeException(noSuchMethodException);
Expand Down Expand Up @@ -42,4 +47,13 @@ public static String name(Sound sound) {
}
}

public static NamespacedKey key(Sound sound) {
try {
return (NamespacedKey) keyMethod.invoke(sound);
}
catch (ReflectiveOperationException reflectiveOperationException) {
throw new RuntimeException(reflectiveOperationException);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public NoticeKey<SoundBukkit> noticeKey() {

@Override
public void send(Audience audience, ComponentSerializer<Component, Component, String> componentSerializer, SoundBukkit content) {
String soundKey = content.sound().getKey().getKey();
String soundKey = SoundAccessor.key(content.sound()).getKey();
Sound sound = Sound.sound(
Key.key(soundKey),
Sound.Source.valueOf(content.toKyoriCategory().name()),
Expand Down

0 comments on commit 1220761

Please sign in to comment.