play folders LoL

This commit is contained in:
Chayapak 2023-07-02 10:40:11 +07:00
parent 6acc76171a
commit b7751a5467

View file

@ -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,6 +100,12 @@ public class SongLoaderRunnable implements Runnable {
failed();
} else {
bot.music.songQueue.add(song);
if (!isFolder) showAddedToQueue();
}
}
private void showAddedToQueue () {
bot.chat.tellraw(
Component.translatable(
"Added %s to the song queue",
@ -88,7 +113,6 @@ public class SongLoaderRunnable implements Runnable {
).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor))
);
}
}
private void failed() {
exception.printStackTrace();