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 final boolean isUrl;
private boolean isFolder = false;
public SongLoaderRunnable(URL location, Bot bot) { public SongLoaderRunnable(URL location, Bot bot) {
this.bot = bot; this.bot = bot;
isUrl = true; isUrl = true;
@ -39,10 +41,27 @@ public class SongLoaderRunnable implements Runnable {
isUrl = false; isUrl = false;
songPath = location.toFile(); songPath = location.toFile();
isFolder = songPath.isDirectory();
fileName = location.getFileName().toString(); fileName = location.getFileName().toString();
} }
public void run () { 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; byte[] bytes;
String name; String name;
try { try {
@ -81,15 +100,20 @@ public class SongLoaderRunnable implements Runnable {
failed(); failed();
} else { } else {
bot.music.songQueue.add(song); bot.music.songQueue.add(song);
bot.chat.tellraw(
Component.translatable( if (!isFolder) showAddedToQueue();
"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 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() { private void failed() {
exception.printStackTrace(); exception.printStackTrace();
bot.chat.tellraw(Component.translatable("Failed to load song: %s", exception.message).color(NamedTextColor.RED)); bot.chat.tellraw(Component.translatable("Failed to load song: %s", exception.message).color(NamedTextColor.RED));