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.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class CommandProcessor {
|
public class CommandProcessor {
|
||||||
public static ArrayList<Command> commands = new ArrayList<>();
|
public static ArrayList<Command> commands = new ArrayList<>();
|
||||||
|
@ -173,11 +174,26 @@ public class CommandProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
|
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
|
||||||
List<String> filenames = Arrays.stream(SongPlayer.SONG_DIR.listFiles())
|
int lastSlash = args.lastIndexOf("/");
|
||||||
.filter(File::isFile)
|
String dirString = "";
|
||||||
.map(File::getName)
|
File dir = SongPlayer.SONG_DIR;
|
||||||
.collect(Collectors.toList());
|
if (lastSlash >= 0) {
|
||||||
return CommandSource.suggestMatching(filenames, suggestionsBuilder);
|
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;
|
isUrl = true;
|
||||||
songUrl = new URL(location);
|
songUrl = new URL(location);
|
||||||
}
|
}
|
||||||
else if (location.contains("/") || location.contains("\\")) {
|
|
||||||
throw new IOException("Invalid characters in song name: " + location);
|
|
||||||
}
|
|
||||||
else if (getSongFile(location).exists()) {
|
else if (getSongFile(location).exists()) {
|
||||||
songPath = getSongFile(location);
|
songPath = getSongFile(location);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue