1919import io .github .thebusybiscuit .slimefun4 .implementation .SlimefunItems ;
2020import io .github .thebusybiscuit .slimefun4 .utils .SlimefunUtils ;
2121import java .io .File ;
22+ import java .util .HashSet ;
2223import java .util .Objects ;
24+ import java .util .Set ;
2325import javax .script .ScriptException ;
2426import me .mrCookieSlime .Slimefun .api .inventory .BlockMenu ;
2527import org .graalvm .polyglot .Context ;
3638public class JavaScriptEval extends ScriptEval {
3739 private static final File PLUGINS_FOLDER = RykenSlimefunCustomizer .INSTANCE .getDataFolder ().getParentFile ();
3840 private static final String [] packages = {"io" , "net" };
41+ private final Set <String > failed_functions = new HashSet <>();
3942
4043 private GraalJSScriptEngine jsEngine ;
4144
@@ -117,6 +120,11 @@ public Object evalFunction(String funName, Object... args) {
117120 contextInit ();
118121 }
119122
123+ // a simple fix for the optimization
124+ if (failed_functions .contains (funName )) {
125+ return null ;
126+ }
127+
120128 try {
121129 Object result = jsEngine .invokeFunction (funName , args );
122130 ExceptionHandler .debugLog ("运行了 " + getAddon ().getAddonName () + "的脚本" + getFile ().getName () + "中的函数 " + funName );
@@ -131,6 +139,8 @@ public Object evalFunction(String funName, Object... args) {
131139 ExceptionHandler .handleError ("在运行" + getAddon ().getAddonName () + "的脚本" + getFile ().getName () + "时发生错误" );
132140 e .printStackTrace ();
133141 } catch (NoSuchMethodException ignored ) {
142+ // won't log it, because listeners always send a lot of functions
143+ failed_functions .add (funName );
134144 } catch (Throwable e ) {
135145 ExceptionHandler .handleError ("在运行" + getAddon ().getAddonName () + "的脚本" + getFile ().getName () + "时发生意外错误" );
136146 e .printStackTrace ();
0 commit comments