Skip to content

Commit e9a3c76

Browse files
authored
Merge pull request #114 from TheNextLvl-net/wildcard
Restore wildcard support
2 parents 55fb172 + f8a3e60 commit e9a3c76

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

api/src/main/java/net/thenextlvl/commander/CommandFinder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ public interface CommandFinder {
4545
*/
4646
default @Unmodifiable Set<String> findCommands(Stream<String> commands, String input) {
4747
try {
48-
return findCommands(commands, Pattern.compile(input));
48+
return findCommands(commands, Pattern.compile(input.replace("*", ".*")));
4949
} catch (PatternSyntaxException e) {
50-
return findCommands(commands, Pattern.compile(Pattern.quote(input)));
50+
var escaped = Pattern.quote(input).replace("\\*", "*");
51+
return findCommands(commands, Pattern.compile(escaped.replace("*", ".*")));
5152
}
5253
}
5354

@@ -59,9 +60,10 @@ public interface CommandFinder {
5960
*/
6061
default @Unmodifiable Set<String> findCommands(String input) {
6162
try {
62-
return findCommands(Pattern.compile(input));
63+
return findCommands(Pattern.compile(input.replace("*", ".*")));
6364
} catch (PatternSyntaxException e) {
64-
return findCommands(Pattern.compile(Pattern.quote(input)));
65+
var escaped = Pattern.quote(input).replace("\\*", "*");
66+
return findCommands(Pattern.compile(escaped.replace("*", ".*")));
6567
}
6668
}
6769
}

0 commit comments

Comments
 (0)