Skip to content

Commit 95abe1b

Browse files
committed
Added CommandFramework#setAnyMatch usage to README
1 parent f2737bd commit 95abe1b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To add this project as a dependency to your project, add the following to your p
2828
<dependency>
2929
<groupId>com.github.Despical</groupId>
3030
<artifactId>CommandFramework</artifactId>
31-
<version>1.0.4</version>
31+
<version>1.0.5</version>
3232
<scope>compile</scope>
3333
</dependency>
3434
```
@@ -41,7 +41,7 @@ repositories {
4141
```
4242
```
4343
dependencies {
44-
compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.0.4";
44+
compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.0.5";
4545
}
4646
```
4747

@@ -60,6 +60,18 @@ public class ExampleClass extends JavaPlugin {
6060
// Then this will register all the @Command methods as a command
6161
// so there is no necessity to add command to your plugin.yml
6262
commandFramework.registerCommands(this);
63+
commandFramework.setAnyMatch(arguments -> {
64+
if (arguments.isArgumentsEmpty()) return;
65+
66+
String label = arguments.getLabel(), arg = arguments.getArgument(0);
67+
68+
// StringMatcher is an external class from Despical's Commons library which is not in this framework
69+
ListStringMatcher.Match> matches = StringMatcher.match(arg, commandFramework.getCommands().stream().map(cmd -> cmd.name().replace(label + ".", "")).collect(Collectors.toList()));
70+
71+
if (!matches.isEmpty()) {
72+
arguments.sendMessage("Did you mean %command%?").replace("%command%", label + " " + matches.get(0).getMatch());
73+
}
74+
});
6375
}
6476

6577
// Before creating command the method must only have

0 commit comments

Comments
 (0)