Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

Commit 98e7efb

Browse files
authored
optimize script engine (SlimefunReloadingProject#56)
1 parent 8a0aa33 commit 98e7efb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/bulit_in/JavaScriptEval.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
2020
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
2121
import java.io.File;
22+
import java.util.HashSet;
2223
import java.util.Objects;
24+
import java.util.Set;
2325
import javax.script.ScriptException;
2426
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
2527
import org.graalvm.polyglot.Context;
@@ -36,6 +38,7 @@
3638
public 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

Comments
 (0)