feat: 新增Sponge的部分支持(测试中)

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
2017-10-26 21:01:24 +08:00
parent 4bb2c48021
commit e387863061
18 changed files with 437 additions and 221 deletions

View File

@ -1,26 +1,62 @@
'use strict';
var log = base.getLog().static;
var log;
var boot;
var disable;
/**
* 初始化框架引擎
*/
(function () {
boot = function (plugin) {
boot = function (root, logger) {
log = logger;
// 开发环境下初始化
var root = "src/main/resources";
if (plugin !== null) {
// noinspection JSUnresolvedVariable
root = plugin.dataFolder.canonicalPath;
}
root = root || "src/main/resources";
// 解压文件到根目录
release(root, "[core|modules]/.*", true);
release(root, "plugins/.*");
load(root + '/core/init.js');
try {
init(root);
} catch (ex) {
log.w("MiaoScript 初始化失败! %s", ex);
throw ex;
} finally {
disable = disablePlugins
}
};
function release(root, regex, replace) {
print(Array.prototype.join.call(arguments, ' '));
var Files = Java.type("java.nio.file.Files");
var Paths = Java.type("java.nio.file.Paths");
var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
var classLoader = java.lang.Thread.currentThread().getContextClassLoader();
var url = classLoader.getResource("plugin.yml");
if (url === null) {
return;
}
var upath = url.getFile().substring(url.getFile().indexOf("/") + 1);
var jarPath = java.net.URLDecoder.decode(upath.substring(0, upath.indexOf('!')));
if (!Files.exists(Paths.get(jarPath))) {
jarPath = "/" + jarPath;
}
try {
var jar = new java.util.jar.JarFile(jarPath);
var r = new RegExp(regex);// "[core|modules]/.*"
jar.stream().forEach(function (entry) {
if (!entry.isDirectory()) {
if (r.test(entry.name)) {
var path = Paths.get(root, entry.name);
var parentFile = path.toFile().parentFile;
if (!parentFile.exists()) {
parentFile.mkdirs();
}
Files.copy(classLoader.getResourceAsStream(entry.name), path, StandardCopyOption[replace ? 'REPLACE_EXISTING' : 'ATOMIC_MOVE']);
}
}
})
} catch (ex) {
} finally {
}
}
})();