ProtocolLib

3M Downloads

Unable to cancel NamedSoundEffectPacket

wiji1 opened this issue ยท 1 comments

commented

I'm attempting to cancel all of the Villager idle sound effects that occur on my server. To do this, I am using the following code to cancel all outgoing packets containing the sound

new PacketAdapter(PitSim.INSTANCE, PacketType.Play.Server.NAMED_SOUND_EFFECT) { @Override public void onPacketSending(PacketEvent event) { String soundName = event.getPacket().getStrings().read(0); Bukkit.broadcastMessage(soundName); if(soundName.equals("mob.villager.idle")) { Bukkit.broadcastMessage("."); event.setCancelled(true); } } });

In game, the correct name and the period are both being broadcasted. Additionally, I tried broadcasting event.isCanceled(), to which it returned true. However, the sound still plays in game.

Expected behavior
The sound packet should not be sent to the client.

commented

I was stupid and had another listener that was un-canceling the packets elsewhere in the plugin