diff --git a/pom.xml b/pom.xml
index 0e17dea..6c82e12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
pw.yumc
MiaoScript
- 1.1.1
+ 1.1.2
502647092
diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js
index a3d4289..58c60ed 100644
--- a/src/main/resources/bios.js
+++ b/src/main/resources/bios.js
@@ -14,7 +14,7 @@ var disable;
}
load(root + '/core/init.js');
try {
- init(root, plugin);
+ init(root);
} catch (ex) {
log.w("MiaoScript 初始化失败! %s", ex);
throw ex;
diff --git a/src/main/resources/core/fs.js b/src/main/resources/core/fs.js
index 5d82b65..063debd 100644
--- a/src/main/resources/core/fs.js
+++ b/src/main/resources/core/fs.js
@@ -4,8 +4,15 @@
var String = Java.type("java.lang.String");
var File = Java.type("java.io.File");
var Files = Java.type("java.nio.file.Files");
+var separatorChar = File.separatorChar;
var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
+/**
+ * 用文件分割符合并路径
+ */
+exports.concat = function () {
+ return Array.prototype.join.call(arguments, separatorChar);
+}
/**
* 获得文件
* @constructor(file)
diff --git a/src/main/resources/core/init.js b/src/main/resources/core/init.js
index 5de6693..48abced 100644
--- a/src/main/resources/core/init.js
+++ b/src/main/resources/core/init.js
@@ -3,12 +3,13 @@ var global = this;
/*global base*/
// noinspection JSUnusedLocalSymbols
-function init(root, plugin) {
+function init(root) {
global.root = root;
loadCore();
loadRequire();
+ loadPatch();
loadLib4Bukkit();
- loadPlugins(plugin);
+ loadPlugins();
}
/**
@@ -18,8 +19,6 @@ function loadCore() {
// 加载基础模块
load(root + '/core/ext.js');
load(root + '/core/console.js');
- // 加载补丁和扩展
- load(root + '/core/patch.js');
}
/**
@@ -30,6 +29,17 @@ function loadRequire() {
global.require = load(root + '/core/require.js')(root);
}
+/**
+ * 加载补丁
+ */
+function loadPatch() {
+ // 加载补丁和扩展
+ load(root + '/core/patch.js');
+}
+
+/**
+ * 加载Bukkit的类库
+ */
function loadLib4Bukkit() {
require('modules/event');
var task = require('modules/task');
@@ -50,14 +60,14 @@ function loadLib4Bukkit() {
/**
* 加载JS插件
*/
-function loadPlugins(plugin) {
+function loadPlugins() {
// 初始化本体插件
- global.pluginManager = require('modules/plugin');
- pluginManager.init(plugin, root + '/plugins');
+ global.manager = require('modules/plugin');
+ manager.init(base.plugin, 'plugins');
// 只有当在正式环境运行的时候才加载
- if (pluginManager.$) {
- pluginManager.load();
- pluginManager.enable();
+ if (manager.$) {
+ manager.load();
+ manager.enable();
}
}
@@ -66,7 +76,7 @@ function loadPlugins(plugin) {
* 关闭插件Hook
*/
function disablePlugins() {
- if (pluginManager.$) {
- pluginManager.disable();
+ if (manager.$) {
+ manager.disable();
}
}
\ No newline at end of file
diff --git a/src/main/resources/core/patch.js b/src/main/resources/core/patch.js
index a56e033..3bd730a 100644
--- a/src/main/resources/core/patch.js
+++ b/src/main/resources/core/patch.js
@@ -2,8 +2,11 @@
* 补丁和方法扩展
*/
-// JSON快捷方法
-Object.prototype.toJson = function(){ return JSON.stringify(this); }
+(function(){
+ // JSON快捷方法
+ Object.prototype.toJson = function(){ return JSON.stringify(this); }
-// YAML快速生成
-Object.prototype.toYaml = function(){ return require('modules/yaml').safeDump(this); }
\ No newline at end of file
+ // YAML快速生成
+ var yaml = require('modules/yaml');
+ Object.prototype.toYaml = function(){ return yaml.safeDump(this); }
+})();
diff --git a/src/main/resources/core/require.js b/src/main/resources/core/require.js
index e9495cf..7bc463b 100644
--- a/src/main/resources/core/require.js
+++ b/src/main/resources/core/require.js
@@ -6,7 +6,8 @@
(function (parent) {
'use strict';
var File = Java.type("java.io.File");
- var paths = [parent, '', parent + '/core', parent + '/modules'];
+ var separatorChar = File.separatorChar;
+ var paths = [parent, '', parent + separatorChar + 'core', parent + separatorChar + 'modules'];
/**
* 解析模块名称为文件
@@ -137,7 +138,7 @@
}
function _cacheFile(file) {
- return cacheDir + "/" + file.name;
+ return cacheDir + separatorChar + file.name;
}
/**
@@ -176,7 +177,7 @@
};
}
- var cacheDir = parent + "/runtime";
+ var cacheDir = parent + separatorChar + "runtime";
// 等于 undefined 说明 parent 是一个字符串 需要转成File
// 可能有更加准确的方案
diff --git a/src/main/resources/modules/plugin.js b/src/main/resources/modules/plugin.js
index 3c43c18..2ad06e0 100644
--- a/src/main/resources/modules/plugin.js
+++ b/src/main/resources/modules/plugin.js
@@ -15,15 +15,15 @@ var permission = require('./permission');
* 载入插件
* @param path
*/
-function loadPlugins(path) {
- var plugin = fs.file(path);
+function loadPlugins(dir) {
+ var plugin = fs.file(root, dir);
if (!plugin) {
- log.i("首次加载 创建文件夹 %s ...", path);
+ log.i("首次加载 创建文件夹 %s ...", plugin);
} else {
- log.i("开始扫描 %s 下的插件 ...", path);
- createUpdate(path);
+ log.i("开始扫描 %s 下的插件 ...", plugin);
+ createUpdate(plugin);
var files = [];
- fs.list(path).forEach(function (file) {
+ fs.list(plugin).forEach(function (file) {
files.push(file.toFile());
});
loadZipPlugins(files);