Skip to content

Commit

Permalink
PlayCommand now lists files inside /Songs/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
uoil committed May 20, 2023
1 parent b794ef1 commit a455dc1
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class PlayCommand extends Command {
private final File directory;

public PlayCommand() {
super("Play", new String[]{"playsong", "begin"}, "Plays a song file from your /Seppuku/Songs/ directory.", ".play <song file name>");
super("Play", new String[]{"playsong", "begin"}, "Plays a song file from your /Seppuku/Config/<current config>/Songs/ directory.", ".play <midi file name>");

this.directory = new File(Seppuku.INSTANCE.getConfigManager().getConfigDir(), "Songs");
if (!directory.exists()) {
Expand All @@ -27,6 +27,21 @@ public PlayCommand() {
public void exec(String input) {
if (!this.clamp(input, 2, 2)) {
this.printUsage();
if (!this.directory.exists())
return;
final StringBuilder listedFilesBuilder = new StringBuilder();
final String[] fileList = this.directory.list();
if (fileList == null)
return;
if (fileList.length == 0 || fileList.length > 100)
return;
for (int i = 0; i < fileList.length; i++) {
String s = fileList[i].replaceAll(".midi", "").replaceAll(".mid", "");
listedFilesBuilder.append(ChatFormatting.GREEN).append(s);
if (i != fileList.length - 1)
listedFilesBuilder.append(ChatFormatting.GRAY).append(", ");
}
Seppuku.INSTANCE.logChat(ChatFormatting.GRAY + listedFilesBuilder.toString());
return;
}

Expand Down

0 comments on commit a455dc1

Please sign in to comment.