@@ -143,39 +143,39 @@ public void unregister(boolean subcommands) {
143143 * This method is called to get the name of the command.
144144 * @return The name of the command.
145145 */
146- protected final String getName () {
146+ public final String getName () {
147147 return name ;
148148 }
149149
150150 /**
151151 * This method is called to get the description of the command.
152152 * @return The description of the command.
153153 */
154- protected final String getDescription () {
154+ public final String getDescription () {
155155 return description ;
156156 }
157157
158158 /**
159159 * This method is called to get the permission of the command.
160160 * @return The permission of the command.
161161 */
162- protected final String getPermission () {
162+ public final String getPermission () {
163163 return permission ;
164164 }
165165
166166 /**
167167 * This method is called to get the usage of the command.
168168 * @return The usage of the command.
169169 */
170- protected final String getUsage () {
170+ public final String getUsage () {
171171 return usage ;
172172 }
173173
174174 /**
175175 * This method is called to get the aliases of the command.
176176 * @return The aliases of the command.
177177 */
178- protected final List <String > getAliases () {
178+ public final List <String > getAliases () {
179179 return aliases ;
180180 }
181181
@@ -184,47 +184,47 @@ protected final List<String> getAliases() {
184184 * This method is called to get the subcommands of the command.
185185 * @return The subcommands of the command.
186186 */
187- protected final List <Command <?>> getSubcommands () {
187+ public final List <Command <?>> getSubcommands () {
188188 return subcommands ;
189189 }
190190
191191 /**
192192 * This method is called to get the arguments of the command.
193193 * @return The arguments of the command.
194194 */
195- protected final List <Argument > getArgs () {
195+ public final List <Argument > getArgs () {
196196 return args ;
197197 }
198198
199199 /**
200200 * This method is called to get the optional arguments of the command.
201201 * @return The optional arguments of the command.
202202 */
203- protected final List <Argument > getOptinalArgs () {
203+ public final List <Argument > getOptinalArgs () {
204204 return optionalArgs ;
205205 }
206206
207207 /**
208208 * This method is called to check if the command is only to use in game.
209209 * @return If the command is only to use in game.
210210 */
211- protected final boolean inGameOnly () {
211+ public final boolean inGameOnly () {
212212 return gameOnly ;
213213 }
214214
215215 /**
216216 * This method is called to get the requirements of the command.
217217 * @return The requirements of the command.
218218 */
219- protected final List <Requirement > getRequirements () {
219+ public final List <Requirement > getRequirements () {
220220 return requirements ;
221221 }
222222
223223 /**
224224 * This method is called to check if the command has infinite arguments.
225225 * @return If the command has infinite arguments.
226226 */
227- protected final boolean isInfiniteArgs () {
227+ public final boolean isInfiniteArgs () {
228228 return infiniteArgs ;
229229 }
230230
@@ -290,49 +290,110 @@ public final void addSubCommand(Command<?>... commands) {
290290 * This method is called to add arguments to the command.
291291 * @param args The arguments to add.
292292 */
293- public final void addArgs (String ... args ) {
294- Arrays .asList (args ).forEach (arg -> this .addArgs (arg , null ));
293+ public final void addArgs (Object ... args ) {
294+ if (args .length % 2 != 0 && !(args [1 ] instanceof String )) {
295+ throw new IllegalArgumentException ("You must provide a type for the argument." );
296+ }
297+
298+ for (int i = 0 ; i < args .length ; i += 2 ) {
299+ if (!(args [i ] instanceof String && args [i + 1 ] instanceof Class <?>)) {
300+ throw new IllegalArgumentException ("You must provide a type for the argument." );
301+ }
302+ this .addArgs ((String ) args [i ], (Class <?>) args [i + 1 ]);
303+ }
304+ }
305+
306+ public final void addArgs (String arg ) {
307+ this .addArgs (arg , null , null );
308+ }
309+
310+ public final void addArgs (String arg , Class <?> type ) {
311+ this .addArgs (arg , type ,null );
312+ }
313+
314+ public final void addArgs (String arg , TabConverter converter ) {
315+ this .addArgs (arg , null , converter );
295316 }
296317
297318 /**
298319 * This method is called to add arguments to the command.
299320 * @param arg The argument to add.
300321 * @param converter The converter of the argument.
301322 */
302- public final void addArgs (String arg , TabConverter converter ) {
303- try {
304- if (this .infiniteArgs ) {
305- throw new ArgsWithInfiniteArgumentException (false );
306- }
323+ public final void addArgs (String arg , Class <?> type , TabConverter converter ) {
324+ if (arg .contains (CommandManager .TYPE_PARSER ) && type != null ) {
325+ throw new IllegalArgumentException ("You can't use the type parser in the command arguments." );
326+ }
327+ if (type == null && !arg .contains (CommandManager .TYPE_PARSER )) {
328+ throw new IllegalArgumentException ("You must provide a type for the argument." );
329+ }
307330
308- if (arg .contains (":infinite" )) {
309- this .infiniteArgs = true ;
310- }
311- this .args .add (new Argument (arg , converter ));
312- } catch (ArgsWithInfiniteArgumentException e ) {
313- this .plugin .getLogger ().severe (e .getMessage ());
331+ if (type != null ) {
332+ arg = arg + CommandManager .TYPE_PARSER + type .getSimpleName ().toLowerCase ();
314333 }
334+
335+ this .add (arg , converter , false );
315336 }
316337
317338 /**
318- * This method is called to add optional arguments to the command.
319- * @param args The optional arguments to add.
339+ * This method is called to add arguments to the command.
340+ * @param args The arguments to add.
320341 */
321- public final void addOptinalArgs (String ... args ) {
322- Arrays .asList (args ).forEach (arg -> this .addOptinalArgs (arg , null ));
342+ public final void addOptionalArgs (Object ... args ) {
343+ if (args .length % 2 != 0 && !(args [1 ] instanceof String )) {
344+ throw new IllegalArgumentException ("You must provide a type for the argument." );
345+ }
346+
347+ for (int i = 0 ; i < args .length ; i += 2 ) {
348+ if (!(args [i ] instanceof String && args [i + 1 ] instanceof Class <?>)) {
349+ throw new IllegalArgumentException ("You must provide a type for the argument." );
350+ }
351+ this .addOptionalArgs ((String ) args [i ], (Class <?>) args [i + 1 ]);
352+ }
353+ }
354+
355+ public final void addOptionalArgs (String arg ) {
356+ this .addOptionalArgs (arg , null , null );
357+ }
358+
359+ public final void addOptionalArgs (String arg , Class <?> type ) {
360+ this .addOptionalArgs (arg , type ,null );
361+ }
362+
363+ public final void addOptionalArgs (String arg , TabConverter converter ) {
364+ this .addOptionalArgs (arg , null , converter );
323365 }
324366
325367 /**
326- * This method is called to add optional arguments to the command.
327- * @param arg The optional argument to add.
368+ * This method is called to add arguments to the command.
369+ * @param arg The argument to add.
328370 * @param converter The converter of the argument.
329371 */
330- public final void addOptinalArgs (String arg , TabConverter converter ) {
372+ public final void addOptionalArgs (String arg , Class <?> type , TabConverter converter ) {
373+ if (arg .contains (CommandManager .TYPE_PARSER ) && type != null ) {
374+ throw new IllegalArgumentException ("You can't use the type parser in the command arguments." );
375+ }
376+ if (type != null ) {
377+ arg = arg + CommandManager .TYPE_PARSER + type .getSimpleName ().toLowerCase ();
378+ }
379+
380+ this .add (arg , converter , true );
381+ }
382+
383+ private void add (String arg , TabConverter converter , boolean opt ) {
331384 try {
332385 if (this .infiniteArgs ) {
333- throw new ArgsWithInfiniteArgumentException (true );
386+ throw new ArgsWithInfiniteArgumentException (false );
387+ }
388+
389+ if (arg .contains (":infinite" )) {
390+ this .infiniteArgs = true ;
391+ }
392+ if (opt ) {
393+ this .optionalArgs .add (new Argument (arg , converter ));
394+ } else {
395+ this .args .add (new Argument (arg , converter ));
334396 }
335- this .optionalArgs .add (new Argument (arg , converter ));
336397 } catch (ArgsWithInfiniteArgumentException e ) {
337398 this .plugin .getLogger ().severe (e .getMessage ());
338399 }
0 commit comments