Added support for subdirectories in songs folder
This commit is contained in:
parent
2bba096600
commit
b37a50d365
2 changed files with 21 additions and 8 deletions
|
@ -15,6 +15,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CommandProcessor {
|
||||
public static ArrayList<Command> commands = new ArrayList<>();
|
||||
|
@ -173,11 +174,26 @@ public class CommandProcessor {
|
|||
}
|
||||
}
|
||||
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
|
||||
List<String> filenames = Arrays.stream(SongPlayer.SONG_DIR.listFiles())
|
||||
.filter(File::isFile)
|
||||
.map(File::getName)
|
||||
.collect(Collectors.toList());
|
||||
return CommandSource.suggestMatching(filenames, suggestionsBuilder);
|
||||
int lastSlash = args.lastIndexOf("/");
|
||||
String dirString = "";
|
||||
File dir = SongPlayer.SONG_DIR;
|
||||
if (lastSlash >= 0) {
|
||||
dirString = args.substring(0, lastSlash+1);
|
||||
dir = new File(dir, dirString);
|
||||
}
|
||||
|
||||
if (!dir.exists()) return null;
|
||||
|
||||
ArrayList<String> suggestions = new ArrayList<>();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (file.isFile()) {
|
||||
suggestions.add(dirString + file.getName());
|
||||
}
|
||||
else if (file.isDirectory()) {
|
||||
suggestions.add(dirString + file.getName() + "/");
|
||||
}
|
||||
}
|
||||
return CommandSource.suggestMatching(suggestions, suggestionsBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,9 +24,6 @@ public class SongLoaderThread extends Thread{
|
|||
isUrl = true;
|
||||
songUrl = new URL(location);
|
||||
}
|
||||
else if (location.contains("/") || location.contains("\\")) {
|
||||
throw new IOException("Invalid characters in song name: " + location);
|
||||
}
|
||||
else if (getSongFile(location).exists()) {
|
||||
songPath = getSongFile(location);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue