@@ -280,14 +280,13 @@ record Retrieval<T>(
280
280
@ NotNull String name ,
281
281
@ NotNull Class <?>... args
282
282
) {
283
- if (namespace == null ) {
284
- return getFunction (GLOBAL_NAMESPACE , FunctionIdentifier .of (name , false , args ));
283
+ Retrieval <Function <?>> attempt = null ;
284
+ if (namespace != null ) {
285
+ attempt = getFunction (new NamespaceIdentifier (namespace ),
286
+ FunctionIdentifier .of (name , true , args ));
285
287
}
286
-
287
- Retrieval <Function <?>> attempt = getFunction (new NamespaceIdentifier (namespace ),
288
- FunctionIdentifier .of (name , true , args ));
289
- if (attempt .result () == RetrievalResult .NOT_REGISTERED ) {
290
- return getFunction (GLOBAL_NAMESPACE , FunctionIdentifier .of (name , false , args ));
288
+ if (attempt == null || attempt .result () == RetrievalResult .NOT_REGISTERED ) {
289
+ attempt = getFunction (GLOBAL_NAMESPACE , FunctionIdentifier .of (name , false , args ));
291
290
}
292
291
return attempt ;
293
292
}
@@ -312,7 +311,7 @@ record Retrieval<T>(
312
311
return new Retrieval <>(RetrievalResult .NOT_REGISTERED , null , null );
313
312
}
314
313
315
- Set <FunctionIdentifier > candidates = candidates (provided , existing );
314
+ Set <FunctionIdentifier > candidates = candidates (provided , existing , false );
316
315
if (candidates .isEmpty ()) {
317
316
Skript .debug ("Failed to find a function for '%s'" , provided .name );
318
317
return new Retrieval <>(RetrievalResult .NOT_REGISTERED , null , null );
@@ -353,14 +352,45 @@ public Retrieval<Signature<?>> getSignature(
353
352
@ NotNull String name ,
354
353
@ NotNull Class <?>... args
355
354
) {
356
- if (namespace == null ) {
357
- return getSignature (GLOBAL_NAMESPACE , FunctionIdentifier .of (name , false , args ));
355
+ Retrieval <Signature <?>> attempt = null ;
356
+ if (namespace != null ) {
357
+ attempt = getSignature (new NamespaceIdentifier (namespace ),
358
+ FunctionIdentifier .of (name , true , args ), false );
359
+ }
360
+ if (attempt == null || attempt .result () == RetrievalResult .NOT_REGISTERED ) {
361
+ attempt = getSignature (GLOBAL_NAMESPACE , FunctionIdentifier .of (name , false , args ), false );
362
+ }
363
+ return attempt ;
364
+ }
365
+
366
+ /**
367
+ * Gets the signature for a function with the given name and arguments. If no local function is found,
368
+ * checks for global functions. If {@code namespace} is null, only global signatures will be checked.
369
+ * <p>
370
+ * This function checks performs no argument conversions, and is only used for determining whether a
371
+ * signature already exists with the exact specified arguments. In almost all cases, {@link #getSignature(String, String, Class[])}
372
+ * should be used.
373
+ * </p>
374
+ *
375
+ * @param namespace The namespace to get the function from.
376
+ * Usually represents the path of the script this function is registered in.
377
+ * @param name The name of the function.
378
+ * @param args The types of the arguments of the function.
379
+ * @return The signature for the function with the given name and argument types, or null if no such function exists.
380
+ */
381
+ Retrieval <Signature <?>> getExactSignature (
382
+ @ Nullable String namespace ,
383
+ @ NotNull String name ,
384
+ @ NotNull Class <?>... args
385
+ ) {
386
+ Retrieval <Signature <?>> attempt = null ;
387
+ if (namespace != null ) {
388
+ attempt = getSignature (new NamespaceIdentifier (namespace ),
389
+ FunctionIdentifier .of (name , true , args ), true );
358
390
}
359
391
360
- Retrieval <Signature <?>> attempt = getSignature (new NamespaceIdentifier (namespace ),
361
- FunctionIdentifier .of (name , true , args ));
362
- if (attempt .result () == RetrievalResult .NOT_REGISTERED ) {
363
- return getSignature (GLOBAL_NAMESPACE , FunctionIdentifier .of (name , false , args ));
392
+ if (attempt == null || attempt .result () == RetrievalResult .NOT_REGISTERED ) {
393
+ attempt = getSignature (GLOBAL_NAMESPACE , FunctionIdentifier .of (name , false , args ), true );
364
394
}
365
395
return attempt ;
366
396
}
@@ -370,10 +400,12 @@ public Retrieval<Signature<?>> getSignature(
370
400
*
371
401
* @param namespace The namespace to get the function from.
372
402
* @param provided The provided identifier of the function.
403
+ * @param exact When false, will convert arguments to different types to attempt to find a match.
404
+ * When true, will not convert arguments.
373
405
* @return The signature for the function with the given name and argument types, or null if no such signature exists
374
406
* in the specified namespace.
375
407
*/
376
- private Retrieval <Signature <?>> getSignature (@ NotNull NamespaceIdentifier namespace , @ NotNull FunctionIdentifier provided ) {
408
+ private Retrieval <Signature <?>> getSignature (@ NotNull NamespaceIdentifier namespace , @ NotNull FunctionIdentifier provided , boolean exact ) {
377
409
Preconditions .checkNotNull (namespace , "namespace cannot be null" );
378
410
Preconditions .checkNotNull (provided , "provided cannot be null" );
379
411
@@ -383,7 +415,7 @@ private Retrieval<Signature<?>> getSignature(@NotNull NamespaceIdentifier namesp
383
415
return new Retrieval <>(RetrievalResult .NOT_REGISTERED , null , null );
384
416
}
385
417
386
- Set <FunctionIdentifier > candidates = candidates (provided , ns .identifiers .get (provided .name ));
418
+ Set <FunctionIdentifier > candidates = candidates (provided , ns .identifiers .get (provided .name ), exact );
387
419
if (candidates .isEmpty ()) {
388
420
Skript .debug ("Failed to find a signature for '%s'" , provided .name );
389
421
return new Retrieval <>(RetrievalResult .NOT_REGISTERED , null , null );
@@ -415,11 +447,14 @@ private Retrieval<Signature<?>> getSignature(@NotNull NamespaceIdentifier namesp
415
447
*
416
448
* @param provided The provided function.
417
449
* @param existing The existing functions with the same name.
450
+ * @param exact When false, will convert arguments to different types to attempt to find a match.
451
+ * When true, will not convert arguments.
418
452
* @return An unmodifiable list of candidates for the provided function.
419
453
*/
420
454
private static @ Unmodifiable @ NotNull Set <FunctionIdentifier > candidates (
421
455
@ NotNull FunctionIdentifier provided ,
422
- Set <FunctionIdentifier > existing
456
+ Set <FunctionIdentifier > existing ,
457
+ boolean exact
423
458
) {
424
459
Set <FunctionIdentifier > candidates = new HashSet <>();
425
460
@@ -459,8 +494,15 @@ private Retrieval<Signature<?>> getSignature(@NotNull NamespaceIdentifier namesp
459
494
candidateType = candidate .args [i ];
460
495
}
461
496
462
- if (!Converters .converterExists (provided .args [i ], candidateType )) {
463
- continue candidates ;
497
+ Class <?> providedArg = provided .args [i ];
498
+ if (exact ) {
499
+ if (providedArg != candidateType ) {
500
+ continue candidates ;
501
+ }
502
+ } else {
503
+ if (!Converters .converterExists (providedArg , candidateType )) {
504
+ continue candidates ;
505
+ }
464
506
}
465
507
}
466
508
0 commit comments