aadnk / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
287 stars 92 forks source link

Conversion from Bukkit Sound to NMS SoundEffect fails with some sounds #119

Closed nullEuro closed 7 years ago

nullEuro commented 7 years ago

Test case:

try {
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.NAMED_SOUND_EFFECT);
    packet.getSoundEffects().write(0, Sound.ENTITY_SKELETON_HORSE_HURT);
} catch (Exception e) {
    getLogger().log(Level.SEVERE, "ProtocolLib sound serializing failed", e);
}

Relevant stack trace:

java.lang.IllegalStateException: Invalid Sound requested: minecraft:entity.skeleton.horse.hurt
    at net.minecraft.server.v1_11_R1.SoundEffects.a(SourceFile:510) ~[spigot-1.11.jar:git-Spigot-f950f8e-7f31326]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_111]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_111]
    at com.comphenix.protocol.reflect.accessors.DefaultMethodAccessor.invoke(DefaultMethodAccessor.java:16) ~[?:?]

Cause: ProtocolLib tries to generate a resource key by lowercasing the enum constant name and replacing underscores with dots. However, some sound keys do contain underscores (entity.skeleton_horse.hurt for example - there are quite a few actually).

dmulloy2 commented 7 years ago

Damn it Mojang, why'd you have to ruin my perfect pattern? I'll look into a fix.