@@ -48,7 +48,7 @@ public void setUp() {
48
48
@ Test
49
49
void testCommandRegistration () {
50
50
CommandFramework commandFramework = createCommandFramework ();
51
- assertEquals (2 , commandFramework .getCommands ().size ());
51
+ assertEquals (3 , commandFramework .getCommands ().size ());
52
52
}
53
53
54
54
/**
@@ -82,7 +82,12 @@ void testCommandExecutionByPlayer() {
82
82
player .performCommand ("secondAlias" );
83
83
player .assertSaid ("§cRequired argument length is less or greater than needed!" );
84
84
85
+ // no command arguments
85
86
player .performCommand ("nocommandargs" );
87
+
88
+ // custom parameters
89
+ player .performCommand ("customargs test" );
90
+ player .assertSaid ("First parameter is test" );
86
91
}
87
92
88
93
@ AfterEach
@@ -97,6 +102,7 @@ public void tearDown() {
97
102
private CommandFramework createCommandFramework () {
98
103
CommandFramework commandFramework = new CommandFrameworkMock (plugin );
99
104
commandFramework .registerCommands (new ExampleCommand ());
105
+ commandFramework .addCustomParameter (String .class , arguments -> arguments .getArgument (0 ));
100
106
return commandFramework ;
101
107
}
102
108
@@ -130,9 +136,22 @@ public void noCommandArgsTest() {
130
136
Logger .getLogger (this .getClass ().getSimpleName ()).info ("This command is annotated with @NoCommandArguments to run without required parameters." );
131
137
}
132
138
139
+ @ Command (
140
+ name = "customargs" ,
141
+ min = 1
142
+ )
143
+ // Do not forget to annotate with @CustomParameters; otherwise, the method won't be registered.
144
+ @ CustomParameters
145
+ public void customParamCommand (String firstParameter , CommandArguments arguments ) {
146
+ CommandSender sender = arguments .getSender ();
147
+ // Check if arguments are empty; otherwise, firstParameter will return null.
148
+ // CommandArguments parameter can be added to anywhere in method as a parameter.
149
+ sender .sendMessage ("First parameter is " + firstParameter );
150
+ }
151
+
133
152
@ Completer (
134
- name = "example"
135
- , aliases = {"firstAlias" , "secondAlias" }
153
+ name = "example" ,
154
+ aliases = {"firstAlias" , "secondAlias" }
136
155
)
137
156
public List <String > exampleCommandCompletion (CommandArguments arguments ) {
138
157
return Arrays .asList ("first" , "second" , "third" );
0 commit comments