feat: Optimizing Framework Code

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-03-25 17:13:54 +08:00
parent 478bff9599
commit 8cf8dccbe4
5 changed files with 30 additions and 17 deletions

View File

@ -6,4 +6,4 @@
/*global Java, base, module, exports, require*/
function ItemHandlerDefault() {
}
exports = module.exports = Object.assign(new ItemHandlerDefault(), requireInternal('item'));;
exports = module.exports = Object.assign(new ItemHandlerDefault(), requireInternal('item', true));;

View File

@ -43,7 +43,9 @@ var global = this;
throw Error("Error class loader: " + classLoader.class.name + " Please contact the author MiaoWoo!");
} else {
log.info("Class loader compatible: " + classLoader.class.name);
log.info("Parent class loader: " + classLoader.parent.class.name);
if (classLoader.parent) {
log.info("Parent class loader: " + classLoader.parent.class.name);
}
}
return classLoader;
}

View File

@ -5,6 +5,7 @@
(function(global) {
var Arrays = Java.type('java.util.Arrays');
var Level = Java.type('java.util.logging.Level');
var ignoreLogPrefix = ['java.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.'];
global.ConsoleDefault = function ConsoleDefault(name) {
Object.defineProperty(this, 'name', {
get: function() {
@ -44,12 +45,6 @@
}.bind(this))
};
this.stack = function(ex) {
// var exType = toString.call(ex)
// if (exType !== "[object Error]") {
// console.console('§6[WARN] Unknown Type', exType, ex)
// ex.printStackTrace();
// return []
// }
var stack = ex.getStackTrace();
var cache = ['§4' + ex];
if (stack.class) {
@ -61,8 +56,16 @@
fileName = fileName.indexOf('runtime') > -1 ? fileName.split('runtime')[1] : fileName;
cache.push(' §e->§c %s => §4%s:%s'.format(fileName, trace.methodName, trace.lineNumber))
} else {// %s.%s(§4%s:%s§c)
var className = trace.className
className = className.startsWith('jdk.nashorn.internal.scripts') ? className.substr(className.lastIndexOf('$') + 1) : className
var className = trace.className;
if (className.startsWith('jdk.nashorn.internal.scripts')) {
className = className.substr(className.lastIndexOf('$') + 1)
} else {
for (var prefix in ignoreLogPrefix) {
if (className.startsWith(ignoreLogPrefix[prefix])) {
return;
}
}
}
cache.push(' §e->§c %s.%s(§4%s:%s§c)'.format(className, trace.methodName, trace.fileName, trace.lineNumber));
}
});

View File

@ -240,7 +240,7 @@
file = _isFile(file) ? file : resolve(name, path);
optional = Object.assign({ cache: true }, optional);
if (file === undefined) {
throw Error("Can't found module" + name + 'in directory' + path)
throw Error("Can't found module " + name + " in directory " + path)
}
// 重定向文件名称和类型
return getCacheModule(_canonical(file), file.name.split(".")[0], file, optional);

View File

@ -14,13 +14,21 @@ var nmsVersion = Bukkit.server.class.name.split('.')[3];
* 获取NMS类
*/
function nmsCls(name) {
return Java.type(['net.minecraft.server', nmsVersion, name].join('.'));
try {
return Java.type(['net.minecraft.server', nmsVersion, name].join('.'));
} catch (e) {
return base.getClass(['net.minecraft.server', nmsVersion, name].join('.'))
}
};
/**
* 获取OBC类
*/
function obcCls(name) {
return Java.type(['org.bukkit.craftbukkit', nmsVersion, name].join('.'));
try {
return Java.type(['org.bukkit.craftbukkit', nmsVersion, name].join('.'));
} catch (e) {
return base.getClass(['org.bukkit.craftbukkit', nmsVersion, name].join('.'))
}
};
/**
* 插件管理
@ -37,7 +45,7 @@ var plugin = {
* @param name 插件名称
* @returns {*}
*/
get: function (name) {
get: function(name) {
return PluginManager.getPlugin(name);
},
/**
@ -45,7 +53,7 @@ var plugin = {
* @param name 插件名称
* @returns {*}
*/
load: function (name) {
load: function(name) {
var plugin = this.get(name);
if (ext.notNull(plugin) && !plugin.isEnabled()) {
PluginManager.enablePlugin(plugin);
@ -69,7 +77,7 @@ var service = {
* @param name 插件名称
* @returns {*}
*/
get: function (name) {
get: function(name) {
var reg = ServicesManager.getRegistration(base.getClass(name));
return reg && reg.provider || null;
}
@ -131,7 +139,7 @@ function opcommand(player, command) {
/**
* 关闭引擎时执行的操作
*/
function shutdown () {
function shutdown() {
Bukkit.scheduler.cancelTasks(plugin.self);
Bukkit.servicesManager.unregisterAll(plugin.self);
org.bukkit.event.HandlerList.unregisterAll(plugin.self);