Added subdirectory listing to songs
This commit is contained in:
parent
7daf1049ef
commit
c032f4d5ae
2 changed files with 49 additions and 4 deletions
|
@ -421,28 +421,42 @@ public class CommandProcessor {
|
||||||
return "Lists available songs. If an argument is provided, lists all songs in the subdirectory.";
|
return "Lists available songs. If an argument is provided, lists all songs in the subdirectory.";
|
||||||
}
|
}
|
||||||
public boolean processCommand(String args) {
|
public boolean processCommand(String args) {
|
||||||
if (args.length() == 0) {
|
if (!args.contains(" ")) {
|
||||||
List<String> subdirectories = Util.listFilesSilently(SongPlayer.SONG_DIR)
|
Path dir;
|
||||||
|
if (args.length() == 0) {
|
||||||
|
dir = SongPlayer.SONG_DIR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dir = SongPlayer.SONG_DIR.resolve(args);
|
||||||
|
if (!Files.isDirectory(dir)) {
|
||||||
|
SongPlayer.addChatMessage("§cDirectory not found");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> subdirectories = Util.listFilesSilently(dir)
|
||||||
.filter(Files::isDirectory)
|
.filter(Files::isDirectory)
|
||||||
.map(Path::getFileName)
|
.map(Path::getFileName)
|
||||||
.map(Path::toString)
|
.map(Path::toString)
|
||||||
.map(str -> str + "/")
|
.map(str -> str + "/")
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
List<String> songs = Util.listFilesSilently(SongPlayer.SONG_DIR)
|
List<String> songs = Util.listFilesSilently(dir)
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.map(Path::getFileName)
|
.map(Path::getFileName)
|
||||||
.map(Path::toString)
|
.map(Path::toString)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
if (subdirectories.size() == 0 && songs.size() == 0) {
|
if (subdirectories.size() == 0 && songs.size() == 0) {
|
||||||
SongPlayer.addChatMessage("§6No songs found. You can put midi or nbs files in the §3.minecraft/songs §6folder.");
|
SongPlayer.addChatMessage("§bNo songs found. You can put midi or nbs files in the §3.minecraft/songs §6folder.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
SongPlayer.addChatMessage("§6----------------------------------------");
|
||||||
|
SongPlayer.addChatMessage("§eContents of .minecraft/songs/" + args);
|
||||||
if (subdirectories.size() > 0) {
|
if (subdirectories.size() > 0) {
|
||||||
SongPlayer.addChatMessage("§6Subdirectories: §3" + String.join(" ", subdirectories));
|
SongPlayer.addChatMessage("§6Subdirectories: §3" + String.join(" ", subdirectories));
|
||||||
}
|
}
|
||||||
if (songs.size() > 0) {
|
if (songs.size() > 0) {
|
||||||
SongPlayer.addChatMessage("§6Songs: §7" + String.join(", ", songs));
|
SongPlayer.addChatMessage("§6Songs: §7" + String.join(", ", songs));
|
||||||
}
|
}
|
||||||
|
SongPlayer.addChatMessage("§6----------------------------------------");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -450,6 +464,14 @@ public class CommandProcessor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public CompletableFuture<Suggestions> getSuggestions(String args, SuggestionsBuilder suggestionsBuilder) {
|
||||||
|
if (!args.contains(" ")) {
|
||||||
|
return Util.giveSongDirectorySuggestions(args, suggestionsBuilder);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class playlistCommand extends Command {
|
private static class playlistCommand extends Command {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -113,6 +114,28 @@ public class Util {
|
||||||
suggestionsBuilder);
|
suggestionsBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Suggestions> giveSongDirectorySuggestions(String arg, SuggestionsBuilder suggestionsBuilder) {
|
||||||
|
int lastSlash = arg.lastIndexOf("/");
|
||||||
|
String dirString;
|
||||||
|
Path dir = SongPlayer.SONG_DIR;
|
||||||
|
if (lastSlash >= 0) {
|
||||||
|
dirString = arg.substring(0, lastSlash+1);
|
||||||
|
dir = dir.resolve(dirString);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dirString = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<Path> songFiles = listFilesSilently(dir);
|
||||||
|
if (songFiles == null) return null;
|
||||||
|
|
||||||
|
List<String> suggestions = songFiles
|
||||||
|
.filter(Files::isDirectory)
|
||||||
|
.map(path -> dirString + path.getFileName().toString() + "/")
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return CommandSource.suggestMatching(suggestions, suggestionsBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
public static MutableText getStyledText(String str, Style style) {
|
public static MutableText getStyledText(String str, Style style) {
|
||||||
MutableText text = MutableText.of(new LiteralTextContent(str));
|
MutableText text = MutableText.of(new LiteralTextContent(str));
|
||||||
text.setStyle(style);
|
text.setStyle(style);
|
||||||
|
|
Loading…
Reference in a new issue