@@ -62,20 +62,32 @@ private static Class<? extends Enum> getSoundCategoryClass() throws ClassNotFoun
6262 return soundCategoryClass ;
6363 }
6464
65- private static Method getPlaySoundMethod (Class sound , boolean soundcategory ) throws ClassNotFoundException , NoSuchMethodException {
66- Method method = playSoundMethod .get (sound .getName () + soundcategory );
67- if (method == null ){
68- if (soundcategory ) {
69- method = Player .class .getMethod ("playSound" , Location .class , sound ,
65+ private static Method getPlaySoundMethod (Class <?> sound , boolean soundCategory )
66+ throws ClassNotFoundException , NoSuchMethodException {
67+ String cacheKey = sound .getName () + soundCategory ;
68+ Method method = playSoundMethod .get (cacheKey );
69+
70+ if (method == null ) {
71+ //determine whether sound is an enum (pre 1.21.3) or an interface (post 1.21.3)
72+ Class <?> soundParameter = getSoundParameterClass (sound );
73+
74+ if (soundCategory ) {
75+ method = Player .class .getMethod ("playSound" , Location .class , soundParameter ,
7076 getSoundCategoryClass (), float .class , float .class );
7177 } else {
72- method = Player .class .getMethod ("playSound" , Location .class , sound , float .class , float .class );
78+ method = Player .class .getMethod ("playSound" , Location .class , soundParameter ,
79+ float .class , float .class );
7380 }
74- playSoundMethod .put (sound .getName () + soundcategory , method );
81+
82+ playSoundMethod .put (cacheKey , method );
7583 }
7684 return method ;
7785 }
7886
87+ private static Class <?> getSoundParameterClass (Class <?> sound ) {
88+ return Sound .class .isAssignableFrom (sound ) ? Sound .class : sound ;
89+ }
90+
7991 /**
8092 * Returns whether the version of Bukkit is or is after 1.12
8193 * @return version is after 1.12
0 commit comments