mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-23 19:16:14 +01:00
parent
4b78bf6a34
commit
fb2075b774
@ -58,6 +58,10 @@ public final class MinecraftVersion implements Comparable<MinecraftVersion>, Ser
|
||||
* Version 1.17 - caves and cliffs part 1
|
||||
*/
|
||||
public static final MinecraftVersion CAVES_CLIFFS_1 = new MinecraftVersion("1.17");
|
||||
/**
|
||||
* Version 1.16.4
|
||||
*/
|
||||
public static final MinecraftVersion NETHER_UPDATE_4 = new MinecraftVersion("1.16.4");
|
||||
/**
|
||||
* Version 1.16.2 - breaking change to the nether update
|
||||
*/
|
||||
|
@ -1083,19 +1083,19 @@ public class BukkitConverters {
|
||||
});
|
||||
}
|
||||
|
||||
private static MethodAccessor getSound = null;
|
||||
private static MethodAccessor getSoundEffect = null;
|
||||
private static FieldAccessor soundKey = null;
|
||||
static MethodAccessor getSound = null;
|
||||
static MethodAccessor getSoundEffect = null;
|
||||
static FieldAccessor soundKey = null;
|
||||
|
||||
private static MethodAccessor getSoundEffectByKey = null;
|
||||
private static MethodAccessor getSoundEffectBySound = null;
|
||||
private static MethodAccessor getSoundByEffect = null;
|
||||
static MethodAccessor getSoundEffectByKey = null;
|
||||
static MethodAccessor getSoundEffectBySound = null;
|
||||
static MethodAccessor getSoundByEffect = null;
|
||||
|
||||
private static Map<String, Sound> soundIndex = null;
|
||||
static Map<String, Sound> soundIndex = null;
|
||||
|
||||
public static EquivalentConverter<Sound> getSoundConverter() {
|
||||
// Try to create sound converter for new versions greater 1.16.4
|
||||
try {
|
||||
if (MinecraftVersion.NETHER_UPDATE_4.atOrAbove()) {
|
||||
if (getSoundEffectByKey == null || getSoundEffectBySound == null || getSoundByEffect == null) {
|
||||
Class<?> craftSound = MinecraftReflection.getCraftSoundClass();
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(craftSound, true);
|
||||
@ -1103,19 +1103,19 @@ public class BukkitConverters {
|
||||
getSoundEffectByKey = Accessors.getMethodAccessor(fuzzy.getMethodByReturnTypeAndParameters(
|
||||
"getSoundEffect",
|
||||
MinecraftReflection.getSoundEffectClass(),
|
||||
new Class<?>[]{String.class}
|
||||
String.class
|
||||
));
|
||||
|
||||
getSoundEffectBySound = Accessors.getMethodAccessor(fuzzy.getMethodByReturnTypeAndParameters(
|
||||
"getSoundEffect",
|
||||
MinecraftReflection.getSoundEffectClass(),
|
||||
new Class<?>[]{Sound.class}
|
||||
Sound.class
|
||||
));
|
||||
|
||||
getSoundByEffect = Accessors.getMethodAccessor(fuzzy.getMethodByReturnTypeAndParameters(
|
||||
"getBukkit",
|
||||
Sound.class,
|
||||
new Class<?>[]{MinecraftReflection.getSoundEffectClass()}
|
||||
MinecraftReflection.getSoundEffectClass()
|
||||
));
|
||||
}
|
||||
|
||||
@ -1133,10 +1133,17 @@ public class BukkitConverters {
|
||||
|
||||
@Override
|
||||
public Sound getSpecific(Object generic) {
|
||||
try {
|
||||
return (Sound) getSoundByEffect.invoke(null, generic);
|
||||
} catch (IllegalStateException ex) {
|
||||
if (ex.getCause() instanceof NullPointerException) {
|
||||
// "null" sounds cause NPEs inside getSoundByEffect
|
||||
return null;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
// Fall back to sound converter from legacy versions before 1.16.4
|
||||
@ -1144,9 +1151,9 @@ public class BukkitConverters {
|
||||
Class<?> craftSound = MinecraftReflection.getCraftSoundClass();
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(craftSound, true);
|
||||
getSound = Accessors.getMethodAccessor(
|
||||
fuzzy.getMethodByReturnTypeAndParameters("getSound", String.class, new Class<?>[]{Sound.class}));
|
||||
fuzzy.getMethodByReturnTypeAndParameters("getSound", String.class, Sound.class));
|
||||
getSoundEffect = Accessors.getMethodAccessor(fuzzy.getMethodByReturnTypeAndParameters("getSoundEffect",
|
||||
MinecraftReflection.getSoundEffectClass(), new Class<?>[]{String.class}));
|
||||
MinecraftReflection.getSoundEffectClass(), String.class));
|
||||
}
|
||||
|
||||
return ignoreNull(new EquivalentConverter<Sound>() {
|
||||
|
@ -570,6 +570,8 @@ public class PacketContainerTest {
|
||||
@Test
|
||||
public void testSoundEffects() {
|
||||
PacketContainer container = new PacketContainer(PacketType.Play.Server.NAMED_SOUND_EFFECT);
|
||||
container.getSoundEffects().optionRead(0);
|
||||
|
||||
container.getSoundEffects().write(0, Sound.ENTITY_CAT_HISS);
|
||||
|
||||
assertEquals(container.getSoundEffects().read(0), Sound.ENTITY_CAT_HISS);
|
||||
|
Loading…
Reference in New Issue
Block a user