@@ -953,9 +953,59 @@ public Vector getSpecific(Object generic) {
953
953
private static MethodAccessor getSoundEffect = null ;
954
954
private static FieldAccessor soundKey = null ;
955
955
956
+ private static MethodAccessor getSoundEffectByKey = null ;
957
+ private static MethodAccessor getSoundEffectBySound = null ;
958
+ private static MethodAccessor getSoundByEffect = null ;
959
+
956
960
private static Map <String , Sound > soundIndex = null ;
957
961
958
962
public static EquivalentConverter <Sound > getSoundConverter () {
963
+ // Try to create sound converter for new versions greater 1.16.4
964
+ try {
965
+ if (getSoundEffectByKey == null || getSoundEffectBySound == null || getSoundByEffect == null ) {
966
+ Class <?> craftSound = MinecraftReflection .getCraftSoundClass ();
967
+ FuzzyReflection fuzzy = FuzzyReflection .fromClass (craftSound , true );
968
+
969
+ getSoundEffectByKey = Accessors .getMethodAccessor (fuzzy .getMethodByParameters (
970
+ "getSoundEffect" ,
971
+ MinecraftReflection .getSoundEffectClass (),
972
+ new Class <?>[]{String .class }
973
+ ));
974
+
975
+ getSoundEffectBySound = Accessors .getMethodAccessor (fuzzy .getMethodByParameters (
976
+ "getSoundEffect" ,
977
+ MinecraftReflection .getSoundEffectClass (),
978
+ new Class <?>[]{Sound .class }
979
+ ));
980
+
981
+ getSoundByEffect = Accessors .getMethodAccessor (fuzzy .getMethodByParameters (
982
+ "getBukkit" ,
983
+ Sound .class ,
984
+ new Class <?>[]{MinecraftReflection .getSoundEffectClass ()}
985
+ ));
986
+ }
987
+
988
+ return ignoreNull (new EquivalentConverter <Sound >() {
989
+
990
+ @ Override
991
+ public Class <Sound > getSpecificType () {
992
+ return Sound .class ;
993
+ }
994
+
995
+ @ Override
996
+ public Object getGeneric (Sound specific ) {
997
+ return getSoundEffectBySound .invoke (null , specific );
998
+ }
999
+
1000
+ @ Override
1001
+ public Sound getSpecific (Object generic ) {
1002
+ return (Sound ) getSoundByEffect .invoke (null , generic );
1003
+ }
1004
+ });
1005
+ } catch (Exception e ) {
1006
+ }
1007
+
1008
+ // Fall back to sound converter from legacy versions before 1.16.4
959
1009
if (getSound == null || getSoundEffect == null ) {
960
1010
Class <?> craftSound = MinecraftReflection .getCraftSoundClass ();
961
1011
FuzzyReflection fuzzy = FuzzyReflection .fromClass (craftSound , true );
0 commit comments