2017-09-23 09:42:16 +00:00
|
|
|
'use strict';
|
|
|
|
var global = this;
|
|
|
|
/*global base*/
|
|
|
|
|
|
|
|
// noinspection JSUnusedLocalSymbols
|
2017-10-23 09:09:24 +00:00
|
|
|
function init(root) {
|
2017-09-23 09:42:16 +00:00
|
|
|
global.root = root;
|
|
|
|
loadCore();
|
|
|
|
loadRequire();
|
2017-10-23 09:09:24 +00:00
|
|
|
loadPatch();
|
2017-10-09 13:17:24 +00:00
|
|
|
loadLib4Bukkit();
|
2017-10-23 09:09:24 +00:00
|
|
|
loadPlugins();
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化核心
|
|
|
|
*/
|
|
|
|
function loadCore() {
|
|
|
|
// 加载基础模块
|
2017-10-17 02:53:51 +00:00
|
|
|
load(root + '/core/ext.js');
|
|
|
|
load(root + '/core/console.js');
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 初始化模块
|
|
|
|
*/
|
|
|
|
function loadRequire() {
|
|
|
|
// 初始化加载器
|
2017-10-17 02:53:51 +00:00
|
|
|
global.require = load(root + '/core/require.js')(root);
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 09:09:24 +00:00
|
|
|
/**
|
|
|
|
* 加载补丁
|
|
|
|
*/
|
|
|
|
function loadPatch() {
|
|
|
|
// 加载补丁和扩展
|
|
|
|
load(root + '/core/patch.js');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 加载Bukkit的类库
|
|
|
|
*/
|
2017-10-09 13:17:24 +00:00
|
|
|
function loadLib4Bukkit() {
|
|
|
|
require('modules/event');
|
|
|
|
var task = require('modules/task');
|
2017-10-17 02:53:51 +00:00
|
|
|
global.setTimeout = function (func, time, _async) {
|
|
|
|
return _async ? task.laterAsync(func, time) : task.later(func, time);
|
2017-10-09 13:17:24 +00:00
|
|
|
};
|
|
|
|
global.clearTimeout = function (task) {
|
|
|
|
task.cancel();
|
|
|
|
};
|
2017-10-17 02:53:51 +00:00
|
|
|
global.setInterval = function (func, time, _async) {
|
|
|
|
return _async ? task.timerAsync(func, time) : task.timer(func, time);
|
2017-10-09 13:17:24 +00:00
|
|
|
};
|
|
|
|
global.clearInterval = function (task) {
|
|
|
|
task.cancel();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-09-23 09:42:16 +00:00
|
|
|
/**
|
|
|
|
* 加载JS插件
|
|
|
|
*/
|
2017-10-23 09:09:24 +00:00
|
|
|
function loadPlugins() {
|
2017-09-23 09:42:16 +00:00
|
|
|
// 初始化本体插件
|
2017-10-23 09:09:24 +00:00
|
|
|
global.manager = require('modules/plugin');
|
|
|
|
manager.init(base.plugin, 'plugins');
|
2017-09-27 12:40:57 +00:00
|
|
|
// 只有当在正式环境运行的时候才加载
|
2017-10-23 09:09:24 +00:00
|
|
|
if (manager.$) {
|
|
|
|
manager.load();
|
|
|
|
manager.enable();
|
2017-09-23 10:30:14 +00:00
|
|
|
}
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// noinspection JSUnusedLocalSymbols
|
|
|
|
/**
|
|
|
|
* 关闭插件Hook
|
|
|
|
*/
|
|
|
|
function disablePlugins() {
|
2017-10-23 09:09:24 +00:00
|
|
|
if (manager.$) {
|
|
|
|
manager.disable();
|
2017-09-27 12:40:57 +00:00
|
|
|
}
|
2017-09-23 09:42:16 +00:00
|
|
|
}
|