diff --git a/pom.xml b/pom.xml index 57ebd78..0c3ebf1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoScript - 0.4.2 + 0.5.0 502647092 @@ -54,6 +54,7 @@ DEV + §620-04-10 §afeat: 默认从 classpath 加载内建的js模块; §620-04-07 §afeat: 默认初始化 内建 nodejs 模块; §620-04-03 §afeat: 优化 框架卸载逻辑; §620-03-31 §afeat: require 新增 内建 nodejs 模块; @@ -178,7 +179,7 @@ org.spigotmc spigot-api - 1.14.4-R0.1-SNAPSHOT + 1.15.2-R0.1-SNAPSHOT org.spongepowered @@ -188,7 +189,7 @@ net.md-5 bungeecord-api - 1.12-SNAPSHOT + 1.15-SNAPSHOT cn.nukkit diff --git a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java index c6e0206..d846c5e 100644 --- a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java +++ b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java @@ -39,7 +39,7 @@ public class ScriptEngine { if (Files.exists(bios)) { this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')"); } else { - this.engine.eval(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bios.js"))); + this.engine.eval("load('classpath:bios.js')"); } engine.invokeFunction("boot", root, logger); } diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index e433a11..528bf08 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -12,7 +12,7 @@ var global = this; log = logger; // Development Env Detect root = root || "src/main/resources"; - if (__FILE__ !== "") { + if (__FILE__.indexOf('!') === -1) { logger.info('Loading custom BIOS file ' + __FILE__); global.debug = true; } @@ -24,14 +24,13 @@ var global = this; global.level = base.read(java.nio.file.Paths.get(root, "level")) logger.info('Set system level to [' + global.level + ']...'); } - // Check Class Loader, Sometimes Server will can't find plugin.yml file + // Check Class Loader, Sometimes Server will can't found plugin.yml file loader = checkClassLoader(); - // Force decompression core|node_modules to folder when not debug mode - release(root, '(core)+/.*', !global.debug); // Async Loading MiaoScript Engine new java.lang.Thread(function() { - load(root + '/core/ployfill.js')(root, logger); - engineDisable = require('@ms/core').default; + java.lang.Thread.currentThread().contextClassLoader = loader; + load('classpath:core/ployfill.js')(root, logger); + engineDisable = require('@ms/core').default || function() { logger.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...') }; }, "MiaoScript thread").start() }; @@ -49,30 +48,4 @@ var global = this; } return classLoader; } - - function release(root, regex, replace) { - var filePath = pluginYml.getFile().substring(pluginYml.getFile().indexOf("/") + 1); - var jarPath = java.net.URLDecoder.decode(filePath.substring(0, filePath.indexOf('!'))); - if (!java.nio.file.Files.exists(java.nio.file.Paths.get(jarPath))) { - jarPath = "/" + jarPath; - } - var jar = new java.util.jar.JarFile(jarPath); - var r = new RegExp(regex); - jar.stream().forEach(function(entry) { - try { - if (!entry.isDirectory()) { - if (r.test(entry.name)) { - var path = java.nio.file.Paths.get(root, entry.name); - var parentFile = path.toFile().parentFile; - if (!parentFile.exists()) { parentFile.mkdirs(); } - if (!java.nio.file.Files.exists(path) || replace) { - java.nio.file.Files.copy(loader.getResourceAsStream(entry.name), path, java.nio.file.StandardCopyOption['REPLACE_EXISTING']); - } - } - } - } catch (ex) { - ex.printStackTrace(); - } - }) - } })(); diff --git a/src/main/resources/core/ployfill.js b/src/main/resources/core/ployfill.js index f2365a2..48b7b03 100644 --- a/src/main/resources/core/ployfill.js +++ b/src/main/resources/core/ployfill.js @@ -13,10 +13,10 @@ global.load = load = function __PreventGlobalLoadFunction__() { throw new Error('Internal engine system not allow use `load` function!'); } global.setGlobal = function(key, value) { global[key] = value; }; // Init console and require - global.console = engineLoad(global.root + '/core/console.js')(logger); + global.console = engineLoad('classpath:core/console.js')(logger); console.log("Loading Engine at Thread", java.lang.Thread.currentThread().name) - global.require = engineLoad(global.root + '/core/require.js')(root); + global.require = engineLoad('classpath:core/require.js')(root); require('@ms/ployfill') require('@ms/nodejs') } -); +) diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js index ced87c7..c47d1fd 100644 --- a/src/main/resources/core/require.js +++ b/src/main/resources/core/require.js @@ -382,6 +382,17 @@ } } } + require.disable = function __DynamicDisable__() { + for (var cacheModule in cacheModules) { + delete cacheModules[cacheModule] + } + cacheModules = undefined; + for (var cacheModule in cacheModuleIds) { + delete cacheModuleIds[cacheModule] + } + cacheModuleIds = undefined; + notFoundModules = undefined; + } return require; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1cbd1fa..9f86cff 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,6 +2,7 @@ name: ${project.artifactId} description: ${project.description} main: ${project.groupId}.${project.artifactId}.${project.artifactId} version: ${project.version} +api-version: 1.13 author: MiaoWoo website: ${ciManagement.url} load: STARTUP