feat: Optimizing Framework Code
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
478bff9599
commit
8cf8dccbe4
@ -6,4 +6,4 @@
|
|||||||
/*global Java, base, module, exports, require*/
|
/*global Java, base, module, exports, require*/
|
||||||
function ItemHandlerDefault() {
|
function ItemHandlerDefault() {
|
||||||
}
|
}
|
||||||
exports = module.exports = Object.assign(new ItemHandlerDefault(), requireInternal('item'));;
|
exports = module.exports = Object.assign(new ItemHandlerDefault(), requireInternal('item', true));;
|
||||||
|
@ -43,8 +43,10 @@ var global = this;
|
|||||||
throw Error("Error class loader: " + classLoader.class.name + " Please contact the author MiaoWoo!");
|
throw Error("Error class loader: " + classLoader.class.name + " Please contact the author MiaoWoo!");
|
||||||
} else {
|
} else {
|
||||||
log.info("Class loader compatible: " + classLoader.class.name);
|
log.info("Class loader compatible: " + classLoader.class.name);
|
||||||
|
if (classLoader.parent) {
|
||||||
log.info("Parent class loader: " + classLoader.parent.class.name);
|
log.info("Parent class loader: " + classLoader.parent.class.name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
(function(global) {
|
(function(global) {
|
||||||
var Arrays = Java.type('java.util.Arrays');
|
var Arrays = Java.type('java.util.Arrays');
|
||||||
var Level = Java.type('java.util.logging.Level');
|
var Level = Java.type('java.util.logging.Level');
|
||||||
|
var ignoreLogPrefix = ['java.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.'];
|
||||||
global.ConsoleDefault = function ConsoleDefault(name) {
|
global.ConsoleDefault = function ConsoleDefault(name) {
|
||||||
Object.defineProperty(this, 'name', {
|
Object.defineProperty(this, 'name', {
|
||||||
get: function() {
|
get: function() {
|
||||||
@ -44,12 +45,6 @@
|
|||||||
}.bind(this))
|
}.bind(this))
|
||||||
};
|
};
|
||||||
this.stack = function(ex) {
|
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 stack = ex.getStackTrace();
|
||||||
var cache = ['§4' + ex];
|
var cache = ['§4' + ex];
|
||||||
if (stack.class) {
|
if (stack.class) {
|
||||||
@ -61,8 +56,16 @@
|
|||||||
fileName = fileName.indexOf('runtime') > -1 ? fileName.split('runtime')[1] : fileName;
|
fileName = fileName.indexOf('runtime') > -1 ? fileName.split('runtime')[1] : fileName;
|
||||||
cache.push(' §e->§c %s => §4%s:%s'.format(fileName, trace.methodName, trace.lineNumber))
|
cache.push(' §e->§c %s => §4%s:%s'.format(fileName, trace.methodName, trace.lineNumber))
|
||||||
} else {// %s.%s(§4%s:%s§c)
|
} else {// %s.%s(§4%s:%s§c)
|
||||||
var className = trace.className
|
var className = trace.className;
|
||||||
className = className.startsWith('jdk.nashorn.internal.scripts') ? className.substr(className.lastIndexOf('$') + 1) : 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));
|
cache.push(' §e->§c %s.%s(§4%s:%s§c)'.format(className, trace.methodName, trace.fileName, trace.lineNumber));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -240,7 +240,7 @@
|
|||||||
file = _isFile(file) ? file : resolve(name, path);
|
file = _isFile(file) ? file : resolve(name, path);
|
||||||
optional = Object.assign({ cache: true }, optional);
|
optional = Object.assign({ cache: true }, optional);
|
||||||
if (file === undefined) {
|
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);
|
return getCacheModule(_canonical(file), file.name.split(".")[0], file, optional);
|
||||||
|
@ -14,13 +14,21 @@ var nmsVersion = Bukkit.server.class.name.split('.')[3];
|
|||||||
* 获取NMS类
|
* 获取NMS类
|
||||||
*/
|
*/
|
||||||
function nmsCls(name) {
|
function nmsCls(name) {
|
||||||
|
try {
|
||||||
return Java.type(['net.minecraft.server', nmsVersion, name].join('.'));
|
return Java.type(['net.minecraft.server', nmsVersion, name].join('.'));
|
||||||
|
} catch (e) {
|
||||||
|
return base.getClass(['net.minecraft.server', nmsVersion, name].join('.'))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 获取OBC类
|
* 获取OBC类
|
||||||
*/
|
*/
|
||||||
function obcCls(name) {
|
function obcCls(name) {
|
||||||
|
try {
|
||||||
return Java.type(['org.bukkit.craftbukkit', nmsVersion, name].join('.'));
|
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 插件名称
|
* @param name 插件名称
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
get: function (name) {
|
get: function(name) {
|
||||||
return PluginManager.getPlugin(name);
|
return PluginManager.getPlugin(name);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -45,7 +53,7 @@ var plugin = {
|
|||||||
* @param name 插件名称
|
* @param name 插件名称
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
load: function (name) {
|
load: function(name) {
|
||||||
var plugin = this.get(name);
|
var plugin = this.get(name);
|
||||||
if (ext.notNull(plugin) && !plugin.isEnabled()) {
|
if (ext.notNull(plugin) && !plugin.isEnabled()) {
|
||||||
PluginManager.enablePlugin(plugin);
|
PluginManager.enablePlugin(plugin);
|
||||||
@ -69,7 +77,7 @@ var service = {
|
|||||||
* @param name 插件名称
|
* @param name 插件名称
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
get: function (name) {
|
get: function(name) {
|
||||||
var reg = ServicesManager.getRegistration(base.getClass(name));
|
var reg = ServicesManager.getRegistration(base.getClass(name));
|
||||||
return reg && reg.provider || null;
|
return reg && reg.provider || null;
|
||||||
}
|
}
|
||||||
@ -131,7 +139,7 @@ function opcommand(player, command) {
|
|||||||
/**
|
/**
|
||||||
* 关闭引擎时执行的操作
|
* 关闭引擎时执行的操作
|
||||||
*/
|
*/
|
||||||
function shutdown () {
|
function shutdown() {
|
||||||
Bukkit.scheduler.cancelTasks(plugin.self);
|
Bukkit.scheduler.cancelTasks(plugin.self);
|
||||||
Bukkit.servicesManager.unregisterAll(plugin.self);
|
Bukkit.servicesManager.unregisterAll(plugin.self);
|
||||||
org.bukkit.event.HandlerList.unregisterAll(plugin.self);
|
org.bukkit.event.HandlerList.unregisterAll(plugin.self);
|
||||||
|
Loading…
Reference in New Issue
Block a user