feat: Core Framework Optimization
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@ -51,7 +51,7 @@
|
|||||||
this.console('§4' + message + ex)
|
this.console('§4' + message + ex)
|
||||||
this.stack(ex).forEach(function(line) {
|
this.stack(ex).forEach(function(line) {
|
||||||
this.console(line)
|
this.console(line)
|
||||||
})
|
}.bind(this))
|
||||||
};
|
};
|
||||||
this.stack = function(ex) {
|
this.stack = function(ex) {
|
||||||
var track = ex ? ex.getStackTrace() : new Error().getStackTrace();
|
var track = ex ? ex.getStackTrace() : new Error().getStackTrace();
|
||||||
|
@ -57,11 +57,11 @@
|
|||||||
};
|
};
|
||||||
// 初始化加载器
|
// 初始化加载器
|
||||||
global.require = engineLoad(root + '/core/require.js')(root);
|
global.require = engineLoad(root + '/core/require.js')(root);
|
||||||
global.requireInternal = function requireInternal(name) {
|
global.requireInternal = function requireInternal(name, ignoreError) {
|
||||||
try {
|
try {
|
||||||
return require(root + '/internal/' + DetectServerType + '/' + name + '.js');
|
return require(root + '/internal/' + DetectServerType + '/' + name + '.js');
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
if (!arguments[1]) { return {} }
|
if (ignoreError) { return {} }
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ var chatMessageTypes;
|
|||||||
var String = Java.type('java.lang.String');
|
var String = Java.type('java.lang.String');
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
/** @namespace bukkit.nmsVersion */
|
|
||||||
nmsChatSerializerClass = bukkit.nmsCls(bukkit.nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer");
|
nmsChatSerializerClass = bukkit.nmsCls(bukkit.nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer");
|
||||||
packetTypeClass = bukkit.nmsCls("PacketPlayOutChat");
|
packetTypeClass = bukkit.nmsCls("PacketPlayOutChat");
|
||||||
var packetTypeConstructor;
|
var packetTypeConstructor;
|
||||||
|
@ -20,6 +20,9 @@ item.create = function () {
|
|||||||
if (isNaN(Number(idOrType))) {
|
if (isNaN(Number(idOrType))) {
|
||||||
idOrType = Material[idOrType];
|
idOrType = Material[idOrType];
|
||||||
}
|
}
|
||||||
|
if (!idOrType) {
|
||||||
|
throw Error('无效的物品ID或枚举!' + arguments[0] + ' => ' + idOrType)
|
||||||
|
}
|
||||||
switch (arguments.length) {
|
switch (arguments.length) {
|
||||||
case 1:
|
case 1:
|
||||||
return new ItemStack(idOrType);
|
return new ItemStack(idOrType);
|
||||||
|
@ -141,6 +141,7 @@ function shutdown () {
|
|||||||
|
|
||||||
exports = module.exports = {
|
exports = module.exports = {
|
||||||
$: Bukkit,
|
$: Bukkit,
|
||||||
|
nmsVersion: nmsVersion,
|
||||||
nmsCls: nmsCls,
|
nmsCls: nmsCls,
|
||||||
obcCls: obcCls,
|
obcCls: obcCls,
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
|
@ -12,7 +12,13 @@ var BukkitRunnable = Java.type("org.bukkit.scheduler.BukkitRunnable");
|
|||||||
*/
|
*/
|
||||||
function create(func) {
|
function create(func) {
|
||||||
if (toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 运行任务
|
* 运行任务
|
||||||
|
1
src/main/resources/internal/internal.d.ts
vendored
1
src/main/resources/internal/internal.d.ts
vendored
@ -32,7 +32,6 @@ interface Server {
|
|||||||
pluginManager;
|
pluginManager;
|
||||||
serviceManager;
|
serviceManager;
|
||||||
servicesManager;
|
servicesManager;
|
||||||
onlinePlayers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Player {
|
interface Player {
|
||||||
|
@ -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() {
|
this.call = function() {
|
||||||
var name = arguments[0];
|
var name = arguments[0];
|
||||||
var params = Array.prototype.slice.call(arguments, 1);
|
var params = Array.prototype.slice.call(arguments, 1);
|
||||||
|
Reference in New Issue
Block a user