From 6f5587c232afc8c10268ad708bbed3c75c2b3e2e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 1 Apr 2023 13:25:51 +0700 Subject: [PATCH] finally fix listing --- .../chipmunk/chayapak/chomens_bot/commands/MusicCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java index 9f542ba..092c4e8 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java @@ -154,9 +154,11 @@ public class MusicCommand implements Command { public Component list (CommandContext context, String[] args) { final String prefix = context.prefix(); - final Path _path = Path.of(root.toString(), String.join(" ", args)); + final Path _path = Path.of(root.toString(), String.join(" ", Arrays.copyOfRange(args, 1, args.length))); final Path path = (args.length < 2) ? root : _path; + if (!path.normalize().startsWith(root.toString())) return Component.text("no").color(NamedTextColor.RED); + final String[] filenames = path.toFile().list(); if (filenames == null) return Component.text("Directory doesn't exist").color(NamedTextColor.RED);