From 11ee79af730ded3e0104bb3c558f7a12c92b4c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20=CA=95=E2=80=A2=CC=81=E1=B4=A5=E2=80=A2=CC=80?= =?UTF-8?q?=CA=94?= <92989284+Waischbrot@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:10:33 +0100 Subject: [PATCH] fix NullPointer when sending custom sounds Texturepacks allow for sending custom sounds. But when sending custom sounds, the line... final String soundName = sound.toString(); ...will throw a NullPointer due to the sound not being present in the Sound Enumeration. This check basicly just prevents this exception from happening. --- .../OldCombatMechanics/module/ModuleAttackSounds.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackSounds.java b/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackSounds.java index 48301723..a66a63f8 100644 --- a/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackSounds.java +++ b/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackSounds.java @@ -66,6 +66,12 @@ public void onPacketSending(PacketEvent packetEvent) { try { final PacketContainer packetContainer = packetEvent.getPacket(); final Sound sound = packetContainer.getSoundEffects().read(0); + + //fix NullpointerException when sending a custom sound + if (sound == null) { + return; + } + final String soundName = sound.toString(); // Works for both string and namespaced key if (blockedSounds.contains(soundName)) {