fix NoSuchMethodException for SoundEffectType.e()

This commit is contained in:
Marco 2021-02-27 12:04:32 +01:00
parent caaef40060
commit 938b2cd401

View File

@ -117,9 +117,23 @@ public class SoundListener implements Listener {
soundType = getStepSound.invoke(nmsBlock, blockData);
}
Object soundEffect = soundType.getClass().getMethod("e").invoke(soundType);
float volume = (float) soundType.getClass().getMethod("a").invoke(soundType);
float pitch = (float) soundType.getClass().getMethod("b").invoke(soundType);
Method soundEffectMethod;
Method volumeMethod;
Method pitchMethod;
try {
soundEffectMethod = soundType.getClass().getMethod("e");
volumeMethod = soundType.getClass().getMethod("a");
pitchMethod = soundType.getClass().getMethod("b");
} catch (NoSuchMethodException ex) {
soundEffectMethod = soundType.getClass().getMethod("getPlaceSound");
volumeMethod = soundType.getClass().getMethod("getVolume");
pitchMethod = soundType.getClass().getMethod("getPitch");
}
Object soundEffect = soundEffectMethod.invoke(soundType);
float volume = (float) volumeMethod.invoke(soundType);
float pitch = (float) pitchMethod.invoke(soundType);
Object soundCategory = Enum.valueOf(NMSReflection.getNMSClass("SoundCategory"), "BLOCKS");
volume = (volume + 1.0f) / 2.0f;
@ -148,4 +162,4 @@ public class SoundListener implements Listener {
ex.printStackTrace();
}
}
}
}