diff options
| author | Krakenied <krakenied1@gmail.com> | 2025-02-01 14:37:58 +0100 |
|---|---|---|
| committer | Krakenied <46192742+Krakenied@users.noreply.github.com> | 2025-05-13 20:34:15 +0200 |
| commit | ce81722883702ae379b2e88e5909195619633831 (patch) | |
| tree | 43903bc8520157e1ca8ee0a319698c107117eb21 /bukkit/src/main/java/com | |
| parent | df7ec1cb1af196123f8e2e228987d60f5da05bc7 (diff) | |
Fail silently if the specified sound doesn't exist
Closes https://github.com/LMBishop/Quests/issues/761
Diffstat (limited to 'bukkit/src/main/java/com')
| -rw-r--r-- | bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/SoundUtils.java | 22 |
1 files changed, 13 insertions, 9 deletions
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; } |
