ProtocolLib

3M Downloads

Get sound in 1.19.4

amadeusmz opened this issue ยท 2 comments

commented

Make sure you're doing the following

  • You're using the latest build for your server version
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

Describe the question
I tried to listen to this packet: PacketType.Play.Server.NAMED_SOUND_EFFECT
and get the sound's name
String name = packet.getSoundEffects().read(0).name();
I get this error

java.lang.NullPointerException: Cannot invoke "org.bukkit.Sound.name()" because the return value of "com.comphenix.protocol.reflect.StructureModifier.read(int)" is null
Parameters:
  net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect@4e19768b[
    b=Direct{net.minecraft.sounds.SoundEffect@3e0cfa0f}
    c=MASTER
    d=-21
    e=536
    f=-34
    g=1.0
    h=1.0
    i=2633112130150026501
  ]

The parameters say there is a sound effect, but the getSoundEffects().read(0) method returns null?
It worked fine in 1.19.2

commented

I believe the issue is that if a string sound is used (e.g. player.playSound(player.getLocation(), "entity.creeper.primed", 1f, 1f); vs player.playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 1f, 1f);, getSoundEffects().read(0) will return null.

This can be fixed by doing a null check before calling any methods on the returned object. It may help if the method was marked as @Nullable.

commented

yeah read(index) is subject to return null