From ce81722883702ae379b2e88e5909195619633831 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Sat, 1 Feb 2025 14:37:58 +0100 Subject: Fail silently if the specified sound doesn't exist Closes https://github.com/LMBishop/Quests/issues/761 --- .../quests/bukkit/util/SoundUtils.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'bukkit/src/main/java/com') diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/SoundUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/SoundUtils.java index 1d8bdc71..17c566ec 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/SoundUtils.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/SoundUtils.java @@ -68,17 +68,21 @@ public class SoundUtils { return; } - Sound sound; - try { - // TODO make per version sound getter - sound = soundCache.computeIfAbsent(parts[0], name -> { - try { - return (Sound) soundValueOfMethod.invoke(null, parts[0]); - } catch (IllegalAccessException | InvocationTargetException e) { + Sound sound = soundCache.computeIfAbsent(parts[0], name -> { + try { + return (Sound) soundValueOfMethod.invoke(null, parts[0]); + } catch (IllegalAccessException | InvocationTargetException e) { + final Throwable cause = e.getCause(); + + if (cause instanceof IllegalArgumentException) { + return null; + } else { throw new IllegalStateException("Sound#valueOf invocation failed", e); } - }); - } catch (IllegalArgumentException ignored) { + } + }); + + if (sound == null) { return; } -- cgit v1.2.3-70-g09d2