feat: Core Framework Optimization

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-03-09 10:28:14 +08:00
parent 8d40a69ac7
commit e455cbf996
8 changed files with 43 additions and 22 deletions

View File

@ -51,7 +51,7 @@
this.console('§4' + message + ex)
this.stack(ex).forEach(function(line) {
this.console(line)
})
}.bind(this))
};
this.stack = function(ex) {
var track = ex ? ex.getStackTrace() : new Error().getStackTrace();

View File

@ -57,11 +57,11 @@
};
// 初始化加载器
global.require = engineLoad(root + '/core/require.js')(root);
global.requireInternal = function requireInternal(name) {
global.requireInternal = function requireInternal(name, ignoreError) {
try {
return require(root + '/internal/' + DetectServerType + '/' + name + '.js');
} catch (ex) {
if (!arguments[1]) { return {} }
if (ignoreError) { return {} }
throw ex;
}
}

View File

@ -10,7 +10,6 @@ var chatMessageTypes;
var String = Java.type('java.lang.String');
function init() {
/** @namespace bukkit.nmsVersion */
nmsChatSerializerClass = bukkit.nmsCls(bukkit.nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer");
packetTypeClass = bukkit.nmsCls("PacketPlayOutChat");
var packetTypeConstructor;

View File

@ -20,6 +20,9 @@ item.create = function () {
if (isNaN(Number(idOrType))) {
idOrType = Material[idOrType];
}
if (!idOrType) {
throw Error('无效的物品ID或枚举!' + arguments[0] + ' => ' + idOrType)
}
switch (arguments.length) {
case 1:
return new ItemStack(idOrType);

View File

@ -141,6 +141,7 @@ function shutdown () {
exports = module.exports = {
$: Bukkit,
nmsVersion: nmsVersion,
nmsCls: nmsCls,
obcCls: obcCls,
plugin: plugin,

View File

@ -12,7 +12,13 @@ var BukkitRunnable = Java.type("org.bukkit.scheduler.BukkitRunnable");
*/
function create(func) {
if (toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
return new BukkitRunnable(func);
return new BukkitRunnable(function() {
try {
func();
} catch (ex) {
console.ex('§4插件执行任务时发生错误', ex);
}
});
};
/**
* 运行任务

View File

@ -32,7 +32,6 @@ interface Server {
pluginManager;
serviceManager;
servicesManager;
onlinePlayers;
}
interface Player {

View File

@ -33,6 +33,19 @@ function Reflect(obj) {
}
};
this.fields = function(declared) {
return declared ? this.class.declaredFields : this.class.fields;
}
this.values = function(declared) {
var cache = {};
var feds = declared ? this.class.declaredFields : this.class.fields;
Java.from(feds).forEach(function(fed) {
cache[fed.name] = this.field(fed.name).get();
}.bind(this))
return cache;
}
this.call = function() {
var name = arguments[0];
var params = Array.prototype.slice.call(arguments, 1);