diff --git a/core/src/mindustry/mod/Mods.java b/core/src/mindustry/mod/Mods.java index d18f32f36b..752a261b77 100644 --- a/core/src/mindustry/mod/Mods.java +++ b/core/src/mindustry/mod/Mods.java @@ -460,7 +460,9 @@ public class Mods implements Loadable{ eachEnabled(mod -> { if(mod.root.child("scripts").exists()){ content.setCurrentMod(mod); - Fi main = mod.root.child("scripts").child("main.js"); + //if there's only one script file, use it (for backwards compatibility); if there isn't, use "main.js" + Array allScripts = mod.root.child("scripts").findAll(f -> f.extEquals("js")); + Fi main = allScripts.size == 1 ? allScripts.first() : mod.root.child("scripts").child("main.js"); if(main.exists() && !main.isDirectory()){ try{ if(scripts == null){ diff --git a/core/src/mindustry/mod/Scripts.java b/core/src/mindustry/mod/Scripts.java index 90bbf0daac..409ea4057e 100644 --- a/core/src/mindustry/mod/Scripts.java +++ b/core/src/mindustry/mod/Scripts.java @@ -5,17 +5,16 @@ import arc.files.*; import arc.struct.*; import arc.util.*; import arc.util.Log.*; - -import java.io.*; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.regex.*; import mindustry.*; import mindustry.mod.Mods.*; import org.mozilla.javascript.*; import org.mozilla.javascript.commonjs.module.*; import org.mozilla.javascript.commonjs.module.provider.*; +import java.io.*; +import java.net.*; +import java.util.regex.*; + public class Scripts implements Disposable{ private final Array blacklist = Array.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk", "runtime", "util.os", "rmi", "security", "org.", "sun.", "beans", "sql", "http", "exec", "compiler", "process", "system", @@ -116,20 +115,20 @@ public class Scripts implements Disposable{ @Override public ModuleSource loadSource(String moduleId, Scriptable paths, Object validator) throws IOException, URISyntaxException{ if(loadedMod == null) return null; - return loadSource(loadedMod, moduleId, loadedMod.root.child("scripts"), validator); + return loadSource(moduleId, loadedMod.root.child("scripts"), validator); } - private ModuleSource loadSource(LoadedMod mod, String moduleId, Fi root, Object validator) throws IOException, URISyntaxException{ + private ModuleSource loadSource(String moduleId, Fi root, Object validator) throws URISyntaxException{ Matcher matched = directory.matcher(moduleId); if(matched.find()){ LoadedMod required = Vars.mods.locateMod(matched.group(1)); String script = matched.group(2); - if(required == null || root == required.root.child("scripts")){ // Mod not found, or already using a mod + if(required == null || root.equals(required.root.child("scripts"))){ // Mod not found, or already using a mod Fi dir = root.child(matched.group(1)); if(!dir.exists()) return null; // Mod and folder not found - return loadSource(mod, script, dir, validator); + return loadSource(script, dir, validator); } - return loadSource(required, script, required.root.child("scripts"), validator); + return loadSource(script, required.root.child("scripts"), validator); } Fi module = root.child(moduleId + ".js");