fix: event execute class type error
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
da07acc6b0
commit
6cf446e54b
@ -77,7 +77,7 @@ export namespace event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name2Class(name: any, event: string) {
|
name2Class(name: any, event: string) {
|
||||||
var eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
|
let eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
|
||||||
if (!eventCls) {
|
if (!eventCls) {
|
||||||
try {
|
try {
|
||||||
eventCls = base.getClass(eventCls);
|
eventCls = base.getClass(eventCls);
|
||||||
@ -94,12 +94,15 @@ export namespace event {
|
|||||||
execute(name, exec, eventCls) {
|
execute(name, exec, eventCls) {
|
||||||
return (...args: any[]) => {
|
return (...args: any[]) => {
|
||||||
try {
|
try {
|
||||||
var time = new Date().getTime()
|
let event = args[args.length - 1];
|
||||||
exec(args[args.length - 1]);
|
if (eventCls.isAssignableFrom(event.getClass())) {
|
||||||
var cost = new Date().getTime() - time;
|
let time = Date.now()
|
||||||
|
exec(event);
|
||||||
|
let cost = Date.now() - time;
|
||||||
if (cost > 20) {
|
if (cost > 20) {
|
||||||
console.console(`§c注意! §6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件 §c耗时 §4${cost}ms !`)
|
console.console(`§c注意! §6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件 §c耗时 §4${cost}ms !`)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console(`§6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件时发生异常 §4${ex}`);
|
console.console(`§6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件时发生异常 §4${ex}`);
|
||||||
console.ex(ex);
|
console.ex(ex);
|
||||||
|
@ -48,6 +48,7 @@ class MiaoScriptCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
|
console.log("Disable MiaoScript Engine...")
|
||||||
this.pluginManager.disable();
|
this.pluginManager.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,13 @@ export namespace interfaces {
|
|||||||
public disable() { }
|
public disable() { }
|
||||||
}
|
}
|
||||||
interface BaseMetadata {
|
interface BaseMetadata {
|
||||||
|
/**
|
||||||
|
* 名称 为空则为对象名称
|
||||||
|
*/
|
||||||
name?: string;
|
name?: string;
|
||||||
|
/**
|
||||||
|
* 支持的服务器列表 为空则代表所有
|
||||||
|
*/
|
||||||
servers?: string[];
|
servers?: string[];
|
||||||
}
|
}
|
||||||
export interface PluginMetadata extends BaseMetadata {
|
export interface PluginMetadata extends BaseMetadata {
|
||||||
@ -50,19 +56,37 @@ export namespace interfaces {
|
|||||||
target?: any;
|
target?: any;
|
||||||
}
|
}
|
||||||
interface ExecMetadata extends BaseMetadata {
|
interface ExecMetadata extends BaseMetadata {
|
||||||
|
/**
|
||||||
|
* 执行器
|
||||||
|
*/
|
||||||
executor?: string;
|
executor?: string;
|
||||||
}
|
}
|
||||||
export interface CommandMetadata extends ExecMetadata {
|
export interface CommandMetadata extends ExecMetadata {
|
||||||
|
/**
|
||||||
|
* 参数列表
|
||||||
|
*/
|
||||||
paramtypes?: string[];
|
paramtypes?: string[];
|
||||||
}
|
}
|
||||||
export interface TabCompleterMetadata extends ExecMetadata {
|
export interface TabCompleterMetadata extends ExecMetadata {
|
||||||
|
/**
|
||||||
|
* 参数列表
|
||||||
|
*/
|
||||||
paramtypes?: string[];
|
paramtypes?: string[];
|
||||||
}
|
}
|
||||||
export interface ListenerMetadata extends ExecMetadata {
|
export interface ListenerMetadata extends ExecMetadata {
|
||||||
}
|
}
|
||||||
export interface ConfigMetadata extends BaseMetadata {
|
export interface ConfigMetadata extends BaseMetadata {
|
||||||
|
/**
|
||||||
|
* 配置文件版本号
|
||||||
|
*/
|
||||||
version?: number;
|
version?: number;
|
||||||
|
/**
|
||||||
|
* 实体变量名称
|
||||||
|
*/
|
||||||
variable?: string;
|
variable?: string;
|
||||||
|
/**
|
||||||
|
* 配置文件格式 默认 yml
|
||||||
|
*/
|
||||||
format?: string;
|
format?: string;
|
||||||
}
|
}
|
||||||
export type PluginLike = Plugin | string;
|
export type PluginLike = Plugin | string;
|
||||||
|
@ -98,7 +98,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
try {
|
try {
|
||||||
if (pl[func]) pl[func].call(pl)
|
if (pl[func]) pl[func].call(pl)
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console(`§6插件 §b${pl.description.name} §6执行 §d${func} §6方法时发生错误 §4${ex}`)
|
console.console(`§6Plugin §b${pl.description.name} §6exec §d${func} §6function error §4${ex}`)
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
this.updatePlugin(file)
|
this.updatePlugin(file)
|
||||||
this.createPlugin(file)
|
this.createPlugin(file)
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.console(`§6插件 §b${file.name} §6初始化时发生错误 §4${ex.message}`)
|
console.console(`§6Plugin §b${file.name} §6initialize error §4${ex.message}`)
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user