From b7751a5467f20b30d7e184ccc93a4cfc0bf616f4 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 2 Jul 2023 10:40:11 +0700 Subject: [PATCH] play folders LoL --- .../chomens_bot/song/SongLoaderRunnable.java | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java index d64205ac..f547dd1e 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/song/SongLoaderRunnable.java @@ -26,6 +26,8 @@ public class SongLoaderRunnable implements Runnable { private final boolean isUrl; + private boolean isFolder = false; + public SongLoaderRunnable(URL location, Bot bot) { this.bot = bot; isUrl = true; @@ -39,10 +41,27 @@ public class SongLoaderRunnable implements Runnable { isUrl = false; songPath = location.toFile(); + isFolder = songPath.isDirectory(); + fileName = location.getFileName().toString(); } public void run () { + if (isFolder && !isUrl) { + final File[] files = songPath.listFiles(); + + if (files != null) { + for (File file : files) { + songPath = file; + processFile(); + } + + showAddedToQueue(); + } + } else processFile(); + } + + private void processFile () { byte[] bytes; String name; try { @@ -81,15 +100,20 @@ public class SongLoaderRunnable implements Runnable { failed(); } else { bot.music.songQueue.add(song); - bot.chat.tellraw( - Component.translatable( - "Added %s to the song queue", - Component.empty().append(song.name).color(ColorUtilities.getColorByString(bot.config.colorPalette.secondary)) - ).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)) - ); + + if (!isFolder) showAddedToQueue(); } } + private void showAddedToQueue () { + bot.chat.tellraw( + Component.translatable( + "Added %s to the song queue", + Component.empty().append(song.name).color(ColorUtilities.getColorByString(bot.config.colorPalette.secondary)) + ).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)) + ); + } + private void failed() { exception.printStackTrace(); bot.chat.tellraw(Component.translatable("Failed to load song: %s", exception.message).color(NamedTextColor.RED));