2017-09-23 09:42:16 +00:00
|
|
|
'use strict';
|
2017-10-26 13:01:24 +00:00
|
|
|
var log;
|
2017-09-14 12:41:34 +00:00
|
|
|
var boot;
|
2018-05-17 10:30:40 +00:00
|
|
|
// noinspection ThisExpressionReferencesGlobalObjectJS
|
2017-11-16 12:28:18 +00:00
|
|
|
var global = this;
|
2017-09-14 12:41:34 +00:00
|
|
|
/**
|
2019-08-29 02:08:29 +00:00
|
|
|
* Init Engine Env
|
2017-09-14 12:41:34 +00:00
|
|
|
*/
|
2019-02-23 16:00:03 +00:00
|
|
|
(function() {
|
2017-11-16 12:28:18 +00:00
|
|
|
var loader;
|
2019-02-23 16:00:03 +00:00
|
|
|
boot = function(root, logger) {
|
2017-11-15 10:40:17 +00:00
|
|
|
log = logger;
|
2019-08-29 02:08:29 +00:00
|
|
|
// Development Env Detect
|
2017-11-15 10:40:17 +00:00
|
|
|
root = root || "src/main/resources";
|
|
|
|
if (__FILE__ !== "<eval>") {
|
2019-02-23 16:00:03 +00:00
|
|
|
logger.info('Loading custom BIOS file ' + __FILE__);
|
2017-11-16 12:28:18 +00:00
|
|
|
global.debug = true;
|
2017-11-15 10:40:17 +00:00
|
|
|
}
|
2017-12-28 08:29:10 +00:00
|
|
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) {
|
2019-02-23 16:00:03 +00:00
|
|
|
logger.info('Running debugging mode...');
|
2017-11-30 05:27:20 +00:00
|
|
|
global.debug = true;
|
|
|
|
}
|
2019-08-29 02:08:29 +00:00
|
|
|
// Check Class Loader, Sometimes Server will can't find plugin.yml file
|
2017-11-15 10:40:17 +00:00
|
|
|
loader = checkClassLoader();
|
2019-08-29 02:08:29 +00:00
|
|
|
// Force decompression core|node_modules to folder when not debug mode
|
2019-04-23 10:44:15 +00:00
|
|
|
release(root, '(core|node_modules)+/.*', !global.debug);
|
2019-08-29 02:08:29 +00:00
|
|
|
// Plugin file decompression to folder when file not exist
|
|
|
|
release(root, '(plugins)+/.*', false);
|
2017-11-15 10:40:17 +00:00
|
|
|
load(root + '/core/init.js');
|
2017-09-23 10:30:14 +00:00
|
|
|
try {
|
2017-10-23 09:09:24 +00:00
|
|
|
init(root);
|
2017-09-23 10:30:14 +00:00
|
|
|
} catch (ex) {
|
2017-11-15 10:40:17 +00:00
|
|
|
ex.printStackTrace();
|
2017-09-23 10:30:14 +00:00
|
|
|
}
|
2017-09-23 09:42:16 +00:00
|
|
|
};
|
2017-10-26 13:01:24 +00:00
|
|
|
|
2017-11-15 10:40:17 +00:00
|
|
|
var pluginYml;
|
|
|
|
|
2017-11-15 13:00:07 +00:00
|
|
|
function checkClassLoader() {
|
2018-05-17 10:30:40 +00:00
|
|
|
// noinspection JSUnresolvedVariable
|
2018-03-18 12:06:52 +00:00
|
|
|
var classLoader = java.lang.Thread.currentThread().contextClassLoader;
|
2017-11-15 10:40:17 +00:00
|
|
|
pluginYml = classLoader.getResource("plugin.yml");
|
|
|
|
if (pluginYml === null) {
|
2019-02-23 16:00:03 +00:00
|
|
|
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);
|
2019-03-25 09:13:54 +00:00
|
|
|
if (classLoader.parent) {
|
|
|
|
log.info("Parent class loader: " + classLoader.parent.class.name);
|
|
|
|
}
|
2017-11-15 10:40:17 +00:00
|
|
|
}
|
|
|
|
return classLoader;
|
|
|
|
}
|
|
|
|
|
2017-10-26 13:01:24 +00:00
|
|
|
function release(root, regex, replace) {
|
2018-05-17 10:30:40 +00:00
|
|
|
var filePath = pluginYml.getFile().substring(pluginYml.getFile().indexOf("/") + 1);
|
|
|
|
var jarPath = java.net.URLDecoder.decode(filePath.substring(0, filePath.indexOf('!')));
|
2017-12-28 08:29:10 +00:00
|
|
|
if (!java.nio.file.Files.exists(java.nio.file.Paths.get(jarPath))) {
|
2017-10-30 12:47:10 +00:00
|
|
|
jarPath = "/" + jarPath;
|
|
|
|
}
|
2017-11-30 05:27:20 +00:00
|
|
|
var jar = new java.util.jar.JarFile(jarPath);
|
|
|
|
var r = new RegExp(regex);// "[core|modules]/.*"
|
2019-02-23 16:00:03 +00:00
|
|
|
jar.stream().forEach(function(entry) {
|
2017-11-30 05:27:20 +00:00
|
|
|
try {
|
2018-05-17 10:30:40 +00:00
|
|
|
// noinspection JSValidateTypes
|
2017-10-26 13:01:24 +00:00
|
|
|
if (!entry.isDirectory()) {
|
|
|
|
if (r.test(entry.name)) {
|
2017-12-28 08:29:10 +00:00
|
|
|
var path = java.nio.file.Paths.get(root, entry.name);
|
2018-05-17 10:30:40 +00:00
|
|
|
// noinspection JSUnresolvedVariable
|
2017-10-26 13:01:24 +00:00
|
|
|
var parentFile = path.toFile().parentFile;
|
2017-11-30 05:27:20 +00:00
|
|
|
if (!parentFile.exists()) { parentFile.mkdirs(); }
|
2017-12-28 08:29:10 +00:00
|
|
|
if (!java.nio.file.Files.exists(path) || replace) {
|
|
|
|
java.nio.file.Files.copy(loader.getResourceAsStream(entry.name), path, java.nio.file.StandardCopyOption['REPLACE_EXISTING']);
|
2017-10-26 13:01:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 05:27:20 +00:00
|
|
|
} catch (ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
})
|
2017-10-26 13:01:24 +00:00
|
|
|
}
|
2019-08-29 02:08:29 +00:00
|
|
|
})();
|