feat: Optimization code
This commit is contained in:
parent
997820d117
commit
c2c17a46d4
@ -1,24 +1,23 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
var log;
|
var log;
|
||||||
var boot;
|
var boot;
|
||||||
var disable;
|
|
||||||
// noinspection ThisExpressionReferencesGlobalObjectJS
|
// noinspection ThisExpressionReferencesGlobalObjectJS
|
||||||
var global = this;
|
var global = this;
|
||||||
/**
|
/**
|
||||||
* 初始化框架引擎
|
* 初始化框架引擎
|
||||||
*/
|
*/
|
||||||
(function () {
|
(function() {
|
||||||
var loader;
|
var loader;
|
||||||
boot = function (root, logger) {
|
boot = function(root, logger) {
|
||||||
log = logger;
|
log = logger;
|
||||||
// 开发环境下初始化
|
// 开发环境下初始化
|
||||||
root = root || "src/main/resources";
|
root = root || "src/main/resources";
|
||||||
if (__FILE__ !== "<eval>") {
|
if (__FILE__ !== "<eval>") {
|
||||||
logger.info('载入自定义 BIOS 文件 ' + __FILE__);
|
logger.info('Loading custom BIOS file ' + __FILE__);
|
||||||
global.debug = true;
|
global.debug = true;
|
||||||
}
|
}
|
||||||
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) {
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) {
|
||||||
logger.info('已开启调试模式!');
|
logger.info('Running debugging mode...');
|
||||||
global.debug = true;
|
global.debug = true;
|
||||||
}
|
}
|
||||||
// 检查类加载器 防止找不到核心文件
|
// 检查类加载器 防止找不到核心文件
|
||||||
@ -40,10 +39,10 @@ var global = this;
|
|||||||
var classLoader = java.lang.Thread.currentThread().contextClassLoader;
|
var classLoader = java.lang.Thread.currentThread().contextClassLoader;
|
||||||
pluginYml = classLoader.getResource("plugin.yml");
|
pluginYml = classLoader.getResource("plugin.yml");
|
||||||
if (pluginYml === null) {
|
if (pluginYml === null) {
|
||||||
log.info("==================== ERROR ====================");
|
engineDisable = function engineDisable() { }
|
||||||
log.info("异常的类加载器: " + classLoader.class.name);
|
throw Error("Error class loader: " + classLoader.class.name + " Please contact the author MiaoWoo!");
|
||||||
log.info("==================== ERROR ====================");
|
} else {
|
||||||
throw Error('MiaoScript核心类库初始化失败 异常的类加载器!');
|
log.info("Class loader compatible: " + classLoader.class.name);
|
||||||
}
|
}
|
||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
@ -56,7 +55,7 @@ var global = this;
|
|||||||
}
|
}
|
||||||
var jar = new java.util.jar.JarFile(jarPath);
|
var jar = new java.util.jar.JarFile(jarPath);
|
||||||
var r = new RegExp(regex);// "[core|modules]/.*"
|
var r = new RegExp(regex);// "[core|modules]/.*"
|
||||||
jar.stream().forEach(function (entry) {
|
jar.stream().forEach(function(entry) {
|
||||||
try {
|
try {
|
||||||
// noinspection JSValidateTypes
|
// noinspection JSValidateTypes
|
||||||
if (!entry.isDirectory()) {
|
if (!entry.isDirectory()) {
|
||||||
|
@ -7,7 +7,7 @@ var ServerType = {
|
|||||||
Sponge: 'sponge'
|
Sponge: 'sponge'
|
||||||
};
|
};
|
||||||
var MServer;
|
var MServer;
|
||||||
var DetectServerType = ServerType.Bukkit;
|
var DetectServerType;
|
||||||
try {
|
try {
|
||||||
MServer = Java.type("org.bukkit.Bukkit");
|
MServer = Java.type("org.bukkit.Bukkit");
|
||||||
DetectServerType = ServerType.Bukkit;
|
DetectServerType = ServerType.Bukkit;
|
||||||
@ -23,9 +23,11 @@ try {
|
|||||||
/**
|
/**
|
||||||
* 尝试加载特殊的Console类
|
* 尝试加载特殊的Console类
|
||||||
*/
|
*/
|
||||||
try {
|
if (DetectServerType) {
|
||||||
|
try {
|
||||||
load(root + '/internal/' + DetectServerType + '/console.js');
|
load(root + '/internal/' + DetectServerType + '/console.js');
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// IGNORE
|
// IGNORE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
global.console = new global.Console();
|
global.console = new global.Console();
|
@ -15,10 +15,10 @@
|
|||||||
loadServerLib();
|
loadServerLib();
|
||||||
loadPlugins();
|
loadPlugins();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console("§4初始化插件基础系统库错误:§c", ex);
|
console.console("§4Init plugin system lib failed! ERROR:§c", ex);
|
||||||
console.ex(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() {
|
function loadRequire() {
|
||||||
global.engineLoad = load;
|
global.engineLoad = load;
|
||||||
global.load = function __denyGlobalLoad__() {
|
global.load = function __PreventGlobalLoadFunction__() {
|
||||||
throw new Error('系统内部不许允许使用 load 如需执行脚本 请使用 engineLoad !');
|
throw new Error('Internal engine system not allow use `load` function!');
|
||||||
};
|
};
|
||||||
// 初始化加载器
|
// 初始化加载器
|
||||||
global.require = engineLoad(root + '/core/require.js')(root);
|
global.require = engineLoad(root + '/core/require.js')(root);
|
||||||
@ -53,7 +53,7 @@
|
|||||||
*/
|
*/
|
||||||
function loadPatch() {
|
function loadPatch() {
|
||||||
java.nio.file.Files.list(new java.io.File(root, 'core/patch').toPath()).forEach(function (path) {
|
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 {
|
try {
|
||||||
load(path.toFile());
|
load(path.toFile());
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
@ -93,7 +93,7 @@
|
|||||||
global.manager.load();
|
global.manager.load();
|
||||||
global.manager.enable();
|
global.manager.enable();
|
||||||
} else {
|
} else {
|
||||||
console.console('§4当前服务器不支持使用MiaoScript插件系统!');
|
console.console('§4Current server does not support MiaoScript plugin system!' + DetectServerType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@
|
|||||||
server.shutdown();
|
server.shutdown();
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console("§3MiaoScript Engine §aShutDown §4Error... ERR: ", ex);
|
console.console("§3MiaoScript engine §ashutdown §4error... ERROR: ", ex);
|
||||||
console.ex(ex);
|
console.ex(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user