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

Commit c329e46

Browse files
committed
fix merge
2 parents d9bb292 + 3e37736 commit c329e46

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.lins.mmmjjkx</groupId>
88
<artifactId>RykenSlimefunCustomizer</artifactId>
9-
<version>19</version>
9+
<version>20</version>
1010
<packaging>jar</packaging>
1111

1212
<name>RykenSlimefunCustomizer</name>

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
1717
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
1818
import java.io.File;
19+
import java.util.HashSet;
1920
import java.util.Objects;
21+
import java.util.Set;
2022
import javax.script.ScriptException;
2123
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
2224
import org.graalvm.polyglot.Context;
@@ -33,6 +35,7 @@
3335
public class JavaScriptEval extends ScriptEval {
3436
private static final File PLUGINS_FOLDER =
3537
RykenSlimefunCustomizer.INSTANCE.getDataFolder().getParentFile();
38+
private final Set<String> failed_functions = new HashSet<>();
3639

3740
private GraalJSScriptEngine jsEngine;
3841

@@ -108,22 +111,30 @@ public Object evalFunction(String funName, Object... args) {
108111
contextInit();
109112
}
110113

111-
if (!jsEngine.getPolyglotContext().getPolyglotBindings().hasMember(funName)) {
114+
// a simple fix for the optimization
115+
if (failed_functions.contains(funName)) {
112116
return null;
113117
}
114118

115119
try {
116-
return jsEngine.invokeFunction(funName, args);
120+
Object result = jsEngine.invokeFunction(funName, args);
121+
ExceptionHandler.debugLog("运行了 " + getAddon().getAddonName() + "的脚本" + getFile().getName() + "中的函数 " + funName);
122+
return result;
117123
} catch (IllegalStateException e) {
118124
String message = e.getMessage();
119125
if (!message.contains("Multi threaded access")) {
120-
ExceptionHandler.handleError("在运行" + getFile().getName() + "时发生错误");
126+
ExceptionHandler.handleError("在运行附属" + getAddon().getAddonName() + "的脚本" + getFile().getName() + "时发生错误");
121127
e.printStackTrace();
122128
}
123129
} catch (ScriptException e) {
124-
ExceptionHandler.handleError("在运行" + getFile().getName() + "时发生错误");
130+
ExceptionHandler.handleError("在运行" + getAddon().getAddonName() + "的脚本" + getFile().getName() + "时发生错误");
125131
e.printStackTrace();
126132
} catch (NoSuchMethodException ignored) {
133+
// won't log it, because listeners always send a lot of functions
134+
failed_functions.add(funName);
135+
} catch (Throwable e) {
136+
ExceptionHandler.handleError("在运行" + getAddon().getAddonName() + "的脚本" + getFile().getName() + "时发生意外错误");
137+
e.printStackTrace();
127138
}
128139

129140
return null;
@@ -147,4 +158,4 @@ private void reSetup() {
147158

148159
advancedSetup();
149160
}
150-
}
161+
}

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/objects/ProjectAddonLoader.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import java.lang.reflect.InvocationTargetException;
88
import java.nio.file.Files;
99
import java.util.ArrayList;
10+
import java.util.HashSet;
1011
import java.util.List;
1112
import java.util.Map;
1213
import java.util.Objects;
14+
import java.util.Set;
15+
1316
import net.bytebuddy.ByteBuddy;
1417
import org.bukkit.Bukkit;
1518
import org.bukkit.configuration.file.YamlConfiguration;
@@ -94,13 +97,26 @@ public ProjectAddonLoader(File dir, Map<String, File> ids) {
9497
}
9598

9699
if (info.contains("pluginDepends")) {
100+
Set<String> unloadedPlugins = new HashSet<>();
97101
pluginDepends = info.getStringList("pluginDepends");
98102
for (String pluginDepend : pluginDepends) {
99103
if (!Bukkit.getPluginManager().isPluginEnabled(pluginDepend)) {
100-
ExceptionHandler.handleError("在名称为 " + name + " 的附属(附属id:" + id + ")中需要插件依赖项 " + pluginDepends
101-
+ ",由于部分依赖项在加载时出错或未安装,导致此附属无法加载!");
102-
return null;
104+
unloadedPlugins.add(pluginDepend);
105+
}
106+
}
107+
108+
if (!unloadedPlugins.isEmpty()) {
109+
StringBuilder message = new StringBuilder("在名称为 " + name + " 的附属(附属id:" + id + ")中需要插件依赖项 ");
110+
for (String pluginDepend : pluginDepends) {
111+
if (unloadedPlugins.contains(pluginDepend)) {
112+
message.append("&c").append(pluginDepend).append("&r ");
113+
} else {
114+
message.append("&a").append(pluginDepend).append("&r ");
115+
}
103116
}
117+
message.append(",由于部分依赖项在加载时出错或未安装,导致此附属无法加载!");
118+
ExceptionHandler.handleError(message.toString());
119+
return null;
104120
}
105121
}
106122

@@ -120,6 +136,7 @@ public ProjectAddonLoader(File dir, Map<String, File> ids) {
120136
if (file.exists()) {
121137
JavaScriptEval eval = new JavaScriptEval(file, addon);
122138

139+
// First letter to uppercase
123140
String listenerName = scriptListener.replaceFirst(
124141
String.valueOf(scriptListener.charAt(0)),
125142
String.valueOf(Character.toUpperCase(scriptListener.charAt(0))));
@@ -136,6 +153,7 @@ public ProjectAddonLoader(File dir, Map<String, File> ids) {
136153
Bukkit.getPluginManager().registerEvents(listenerObj, RykenSlimefunCustomizer.INSTANCE);
137154

138155
addon.setEventListener(listenerObj);
156+
ExceptionHandler.info("成功注册附属 " + addon.getAddonId() + " 的监听脚本 " + file.getName() + "!");
139157
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
140158
throw new RuntimeException(e);
141159
}

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/objects/customs/machine/CustomWorkbench.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ protected void tick(Block b) {}
292292
}
293293

294294
for (int slot : inputMap.keySet()) {
295-
blockMenu.consumeItem(slot, inputMap.get(slot).getAmount());
295+
ItemStack itemStack = blockMenu.getItemInSlot(slot);
296+
if (itemStack != null && itemStack.getType() == Material.AIR) {
297+
blockMenu.consumeItem(slot, inputMap.get(slot).getAmount());
298+
}
296299
}
297300
return recipe;
298301
}

src/main/java/org/lins/mmmjjkx/rykenslimefuncustomizer/objects/yaml/item/ItemReader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public SlimefunItem readEach(String s) {
8484
ExceptionHandler.handleWarning(
8585
"在附属" + addon.getAddonId() + "中加载物品" + s + "时遇到了问题: " + "找不到脚本文件" + file.getName());
8686
} else {
87+
ExceptionHandler.debugLog("加载了附属" + addon.getAddonId() + "中物品" + s + "的脚本文件" + file.getName());
8788
eval = new JavaScriptEval(file, addon);
8889
}
8990
}

0 commit comments

Comments
 (0)