You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Main accessing methods. In Kotlin, methods named get() allows it to
84
86
// access these methods using array notation, as a part of operator overloading.
85
87
// More information about operator overloading in Kotlin can be found here:
@@ -342,7 +344,7 @@ public Optional<String> getRawOptional(String nodeName) {
342
344
}
343
345
returnOptional.of(rawArgsMap.get(nodeName));
344
346
}
345
-
347
+
346
348
/** Unchecked methods. These are the same as the methods above, but use
347
349
* unchecked generics to conform to the type they are declared as. In Java,
348
350
* the normal methods (checked) require casting:
@@ -367,7 +369,7 @@ public Optional<String> getRawOptional(String nodeName) {
367
369
public <T> TgetUnchecked(intindex) {
368
370
return (T) get(index);
369
371
}
370
-
372
+
371
373
/**
372
374
* Returns an argument by its node name
373
375
*
@@ -443,4 +445,55 @@ public <T> Optional<T> getOptionalUnchecked(String nodeName) {
443
445
return (Optional<T>) getOptional(nodeName);
444
446
}
445
447
448
+
/**
449
+
* Returns an argument purely based on its CommandAPI representation. This also attempts to directly cast the argument to the type represented by {@link dev.jorel.commandapi.arguments.AbstractArgument#getPrimitiveType()}
450
+
*
451
+
* @param argumentType The argument instance used to create the argument
452
+
* @return The argument represented by the CommandAPI argument, or null if the argument's clas cannot be cast to the type represented by {@link dev.jorel.commandapi.arguments.AbstractArgument#getPrimitiveType()}
453
+
*/
454
+
@Nullable
455
+
public <T> TgetByArgument(AbstractArgument<T, ?, ?, ?> argumentType) {
* Returns an argument based on its node name. This also attempts to directly cast the argument to the type represented by the {@code argumentType} parameter.
462
+
*
463
+
* @param nodeName The node name of the argument
464
+
* @param argumentType The class that represents the argument
465
+
* @return The argument with the given node name, or null if the argument's class cannot be cast to the type represented by the given {@code argumentType} argument
466
+
*/
467
+
@Nullable
468
+
public <T> TgetByClass(StringnodeName, Class<T> argumentType) {
469
+
Objectargument = get(nodeName);
470
+
returncastArgument(argument, argumentType);
471
+
}
472
+
473
+
/**
474
+
* Returns an argument based on its index. This also attempts to directly cast the argument to the type represented by the {@code argumentType} parameter.
475
+
*
476
+
* @param index The position of the argument
477
+
* @param argumentType The class that represents the argument
478
+
* @return The argument at the given index, or null if the argument's class cannot be cast to the type represented by the given {@code argumentType} argument
479
+
*/
480
+
@Nullable
481
+
public <T> TgetByClass(intindex, Class<T> argumentType) {
0 commit comments