@@ -617,33 +617,73 @@ public static String getName(Method method){
617617
618618 public static Value <?> searchAndCall (Exposable obj , Runtime runtime , String name , Value <?>... args ) throws LoaderError {
619619 Class <?> _class = obj .getClass ();
620- Method [] buffer = _class .getMethods ();
621- LinkedList <String > errors = new LinkedList <>();
622- LinkedList <String > names = new LinkedList <>();
623- for (Method method : buffer ){
624- if (getName (method ).equals (name )){
625- ParameterRules rules = rulesFromMethod (method );
626- ParameterCheckReturn retur = ParameterRules .checkParameters (args , rules , runtime );
627- if (!retur .isError ()){
628- return sandboxFunction (method , obj , rules , runtime ).invoke (retur .getFunctionInput ());
629- }else {
630- errors .add (retur .getMessage ());
631- names .add (name + rules .toString (runtime ));
620+ if (cache .containsKey (_class )) {
621+ LoaderCache cachedObject = cache .get (_class );
622+ for (StaticFunctionCache functionCache : cachedObject .functions ()){
623+ if (functionCache .functionName ().equals (name )){
624+ ParameterCheckReturn retur = ParameterRules .checkParameters (args , functionCache .ruleset (), runtime );
625+ if (!retur .isError ()){
626+ return sandboxFunction (functionCache .method (), obj , functionCache .ruleset (), runtime ).invoke (retur .getFunctionInput ());
627+ }else {
628+ return Value .asError (retur .getMessage ());
629+ }
632630 }
633631 }
634- }
635- if (errors .isEmpty ()){
636- return Value .asError ("Cant Find Function '" +name +"'" );
637- }else if (errors .size ()==1 ){
638- return Value .asError (errors .getFirst ());
632+ LinkedList <String > errors = new LinkedList <>();
633+ LinkedList <String > names = new LinkedList <>();
634+ for (PackedFunctionCache pFunctionCache : cachedObject .packedFunctions ()){
635+ if (pFunctionCache .name .equals (name )){
636+ for (StaticFunctionCache functionCache : pFunctionCache .functions ){
637+ ParameterCheckReturn retur = ParameterRules .checkParameters (args , functionCache .ruleset (), runtime );
638+ if (!retur .isError ()){
639+ return sandboxFunction (functionCache .method (), obj , functionCache .ruleset (), runtime ).invoke (retur .getFunctionInput ());
640+ }else {
641+ errors .add (retur .getMessage ());
642+ names .add (name + functionCache .ruleset ().toString (runtime ));
643+ }
644+ }
645+ }
646+ }
647+ if (!errors .isEmpty ()){
648+ names .sort (String ::compareTo );
649+ StringBuilder error = new StringBuilder (errors .get (new Random ().nextInt (errors .size ())));
650+ for (String string : names ){
651+ error .append ('\n' );
652+ error .append (string );
653+ }
654+ return new Exception (error .toString ()).asValue ();
655+ }else {
656+ return Value .asError ("Cant Find Function '" +name +"'" );
657+ }
639658 }else {
640- names .sort (String ::compareTo );
641- StringBuilder error = new StringBuilder (errors .get (new Random ().nextInt (errors .size ())));
642- for (String string : names ){
643- error .append ('\n' );
644- error .append (string );
659+ Method [] buffer = _class .getMethods ();
660+ LinkedList <String > errors = new LinkedList <>();
661+ LinkedList <String > names = new LinkedList <>();
662+ for (Method method : buffer ){
663+ if (getName (method ).equals (name )){
664+ ParameterRules rules = rulesFromMethod (method );
665+ ParameterCheckReturn retur = ParameterRules .checkParameters (args , rules , runtime );
666+ if (!retur .isError ()){
667+ return sandboxFunction (method , obj , rules , runtime ).invoke (retur .getFunctionInput ());
668+ }else {
669+ errors .add (retur .getMessage ());
670+ names .add (name + rules .toString (runtime ));
671+ }
672+ }
673+ }
674+ if (errors .isEmpty ()){
675+ return Value .asError ("Cant Find Function '" +name +"'" );
676+ }else if (errors .size ()==1 ){
677+ return Value .asError (errors .getFirst ());
678+ }else {
679+ names .sort (String ::compareTo );
680+ StringBuilder error = new StringBuilder (errors .get (new Random ().nextInt (errors .size ())));
681+ for (String string : names ){
682+ error .append ('\n' );
683+ error .append (string );
684+ }
685+ return new Exception (error .toString ()).asValue ();
645686 }
646- return new Exception (error .toString ()).asValue ();
647687 }
648688 }
649689
0 commit comments