@@ -37,7 +37,7 @@ To add this project as a dependency to your project, add the following to your p
37
37
<dependency >
38
38
<groupId >com.github.Despical</groupId >
39
39
<artifactId >CommandFramework</artifactId >
40
- <version >1.2.9 </version >
40
+ <version >1.3.0 </version >
41
41
<scope >compile</scope >
42
42
</dependency >
43
43
```
@@ -50,12 +50,17 @@ repositories {
50
50
```
51
51
```
52
52
dependencies {
53
- compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.2.9 ";
53
+ compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.3.0 ";
54
54
}
55
55
```
56
56
57
57
## Example usage
58
+
58
59
``` java
60
+ import me.despical.commandframework.Command ;
61
+ import me.despical.commandframework.CommandArguments ;
62
+ import me.despical.commandframework.CustomParameters ;
63
+
59
64
public class ExampleClass extends JavaPlugin {
60
65
61
66
// Don't forget to shade framework in to your project
@@ -65,6 +70,9 @@ public class ExampleClass extends JavaPlugin {
65
70
public void onEnable () {
66
71
// Initialize the framework before using
67
72
commandFramework = new CommandFramework (this );
73
+ // Adding custom parameters
74
+ // Now all String type objects will return first argument.
75
+ commandFramework. addCustomParameter(String . class, arguments - > arguments. getArgument(0 ));
68
76
69
77
// Then this will register all the @Command methods as a command
70
78
// so there is no necessity to add command to your plugin.yml
@@ -73,9 +81,9 @@ public class ExampleClass extends JavaPlugin {
73
81
if (arguments. isArgumentsEmpty()) return false ;
74
82
75
83
String label = arguments. getLabel(), arg = arguments. getArgument(0 );
76
-
84
+
77
85
// StringMatcher is an external class from Despical's Commons library which is not in this framework
78
- ListStringMatcher . Match > matches = StringMatcher . match(arg, commandFramework. getCommands(). stream(). map(cmd - > cmd. name(). replace(label + " ." , " " )). collect(Collectors . toList()));
86
+ ListStringMatcher . Match > matches = StringMatcher . match(arg, commandFramework. getCommands(). stream(). map(cmd - > cmd. name(). replace(label + " ." , " " )). collect(Collectors . toList()));
79
87
80
88
if (! matches. isEmpty()) {
81
89
arguments. sendMessage(" Did you mean %command%?" . replace(" %command%" , label + " " + matches. get(0 ). getMatch()));
@@ -119,10 +127,21 @@ public class ExampleClass extends JavaPlugin {
119
127
Logger . getLogger(this . getClass(). getSimpleName()). info(" This command is annotated with @NoCommandArguments to run without required parameters." );
120
128
}
121
129
130
+ @Command (
131
+ name = " customargs" ,
132
+ min = 1
133
+ )
134
+ // Do not forget to annotate with @CustomParameters; otherwise, the method won't be registered.
135
+ @CustomParameters
136
+ public void customParamCommand (String firstParameter , CommandArguments arguments ) {
137
+ // CommandArguments parameter can be added to anywhere in method as a parameter.
138
+ arguments. sendMessage(" First parameter is " + firstParameter);
139
+ }
140
+
122
141
// Aliases don't need to be same with the command above
123
142
@Completer (
124
- name = " example" ,
125
- aliases = {" firstAlias" , " secondAlias" }
143
+ name = " example" ,
144
+ aliases = {" firstAlias" , " secondAlias" }
126
145
)
127
146
public List<String > exampleCommandCompletion (CommandArguments arguments ) {
128
147
// And you've created a tab completion for the command above
0 commit comments