From c2c17a46d40cf2ba92045d455f9f496c802cbabb Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sat, 23 Feb 2019 16:00:03 +0000 Subject: [PATCH] feat: Optimization code --- src/main/resources/bios.js | 19 +++++++++---------- src/main/resources/core/detect.js | 12 +++++++----- src/main/resources/core/init.js | 14 +++++++------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index 9884777..790f019 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -1,24 +1,23 @@ 'use strict'; var log; var boot; -var disable; // noinspection ThisExpressionReferencesGlobalObjectJS var global = this; /** * 初始化框架引擎 */ -(function () { +(function() { var loader; - boot = function (root, logger) { + boot = function(root, logger) { log = logger; // 开发环境下初始化 root = root || "src/main/resources"; if (__FILE__ !== "") { - logger.info('载入自定义 BIOS 文件 ' + __FILE__); + logger.info('Loading custom BIOS file ' + __FILE__); global.debug = true; } if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) { - logger.info('已开启调试模式!'); + logger.info('Running debugging mode...'); global.debug = true; } // 检查类加载器 防止找不到核心文件 @@ -40,10 +39,10 @@ var global = this; var classLoader = java.lang.Thread.currentThread().contextClassLoader; pluginYml = classLoader.getResource("plugin.yml"); if (pluginYml === null) { - log.info("==================== ERROR ===================="); - log.info("异常的类加载器: " + classLoader.class.name); - log.info("==================== ERROR ===================="); - throw Error('MiaoScript核心类库初始化失败 异常的类加载器!'); + engineDisable = function engineDisable() { } + throw Error("Error class loader: " + classLoader.class.name + " Please contact the author MiaoWoo!"); + } else { + log.info("Class loader compatible: " + classLoader.class.name); } return classLoader; } @@ -56,7 +55,7 @@ var global = this; } var jar = new java.util.jar.JarFile(jarPath); var r = new RegExp(regex);// "[core|modules]/.*" - jar.stream().forEach(function (entry) { + jar.stream().forEach(function(entry) { try { // noinspection JSValidateTypes if (!entry.isDirectory()) { diff --git a/src/main/resources/core/detect.js b/src/main/resources/core/detect.js index bce6082..42e0449 100644 --- a/src/main/resources/core/detect.js +++ b/src/main/resources/core/detect.js @@ -7,7 +7,7 @@ var ServerType = { Sponge: 'sponge' }; var MServer; -var DetectServerType = ServerType.Bukkit; +var DetectServerType; try { MServer = Java.type("org.bukkit.Bukkit"); DetectServerType = ServerType.Bukkit; @@ -23,9 +23,11 @@ try { /** * 尝试加载特殊的Console类 */ -try { - load(root + '/internal/' + DetectServerType + '/console.js'); -} catch (ex) { - // IGNORE +if (DetectServerType) { + try { + load(root + '/internal/' + DetectServerType + '/console.js'); + } catch (ex) { + // IGNORE + } } global.console = new global.Console(); \ No newline at end of file diff --git a/src/main/resources/core/init.js b/src/main/resources/core/init.js index e38f4f4..ace6f58 100644 --- a/src/main/resources/core/init.js +++ b/src/main/resources/core/init.js @@ -15,10 +15,10 @@ loadServerLib(); loadPlugins(); } catch (ex) { - console.console("§4初始化插件基础系统库错误:§c", ex); + console.console("§4Init plugin system lib failed! ERROR:§c", ex); console.ex(ex); } - console.log('MiaoScript Engine Load Complete... Done (' + (new Date().getTime() - startTime) / 1000 + 's)!'); + console.log('MiaoScript engine loading completed... Done (' + (new Date().getTime() - startTime) / 1000 + 's)!'); }; /** @@ -38,8 +38,8 @@ */ function loadRequire() { global.engineLoad = load; - global.load = function __denyGlobalLoad__() { - throw new Error('系统内部不许允许使用 load 如需执行脚本 请使用 engineLoad !'); + global.load = function __PreventGlobalLoadFunction__() { + throw new Error('Internal engine system not allow use `load` function!'); }; // 初始化加载器 global.require = engineLoad(root + '/core/require.js')(root); @@ -53,7 +53,7 @@ */ function loadPatch() { java.nio.file.Files.list(new java.io.File(root, 'core/patch').toPath()).forEach(function (path) { - console.log('加载扩展类库', path); + console.log('Loading ext lib', path); try { load(path.toFile()); } catch (ex) { @@ -93,7 +93,7 @@ global.manager.load(); global.manager.enable(); } else { - console.console('§4当前服务器不支持使用MiaoScript插件系统!'); + console.console('§4Current server does not support MiaoScript plugin system!' + DetectServerType); } } @@ -111,7 +111,7 @@ server.shutdown(); } } catch (ex) { - console.console("§3MiaoScript Engine §aShutDown §4Error... ERR: ", ex); + console.console("§3MiaoScript engine §ashutdown §4error... ERROR: ", ex); console.ex(ex); } }