From 389a00e0aed4415c1466747e02189874881c5838 Mon Sep 17 00:00:00 2001 From: Ciro Diaz Date: Fri, 26 Apr 2024 16:58:17 +0200 Subject: [PATCH] Implement new sound Mission! New sound!! --- src/main/java/net/op/sound/SoundManager.java | 29 +++++++++++++++++--- src/main/java/net/op/sound/Tracks.java | 10 +++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/op/sound/SoundManager.java b/src/main/java/net/op/sound/SoundManager.java index 18405a5..3f885fe 100644 --- a/src/main/java/net/op/sound/SoundManager.java +++ b/src/main/java/net/op/sound/SoundManager.java @@ -11,7 +11,7 @@ public class SoundManager { public static boolean MUSIC = false; private static Thread currentSoundThread = null; - + private SoundManager() { } @@ -21,9 +21,13 @@ public static void init() { } public static void update() { - if (!MUSIC) + if (!MUSIC) { + if (currentSoundThread != null) + stopSounds(); + return; - + } + if (currentSoundThread != null) { if (currentSoundThread.isAlive()) return; @@ -38,6 +42,23 @@ public static void update() { } + @SuppressWarnings("deprecation") + public static void stopSounds() { + if (currentSoundThread == null) + return; + + try { + currentSoundThread.stop(); + } catch (Exception ignored) { + try { + currentSoundThread.interrupt(); + } catch (Exception ignored2) { + } + } + + currentSoundThread = null; + } + private static boolean mt_PlaySound(Sound sound) { try { Runnable soundRunnable = () -> { @@ -68,7 +89,7 @@ public static boolean playSound(Sound sound, boolean multithreading) { return state; } - + public static boolean playSound(Sound sound) { return playSound(sound, true); } diff --git a/src/main/java/net/op/sound/Tracks.java b/src/main/java/net/op/sound/Tracks.java index a744c44..11a8053 100644 --- a/src/main/java/net/op/sound/Tracks.java +++ b/src/main/java/net/op/sound/Tracks.java @@ -12,15 +12,21 @@ public class Tracks { List menu_sounds = new ArrayList<>(); menu_sounds.add(Sound.of() .name("Menu 2") - .resource("opencraft.sound:menu_2") + .resource("opencraft:sounds.menu_2") .path("/newmusic/menu2.ogg") .build()); menu_sounds.add(Sound.of() .name("Menu 3") - .resource("opencraft.sound:menu_3") + .resource("opencraft:sounds.menu_3") .path("/newmusic/menu3.ogg") .build()); + + menu_sounds.add(Sound.of() + .name("Mission") + .resource("opencraft:sounds.mission") + .path("/music/mission.ogg") + .build()); menu = new Track("Menu Sounds", menu_sounds); }