From f8418798a2b5b022fc48c903e0a64d6735d5cb10 Mon Sep 17 00:00:00 2001 From: coding Date: Fri, 5 Jan 2018 11:27:17 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/api/event.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/resources/api/event.js b/src/main/resources/api/event.js index 782042d..ad9efe2 100644 --- a/src/main/resources/api/event.js +++ b/src/main/resources/api/event.js @@ -91,6 +91,17 @@ function EventHandlerDefault() { throw new Error("当前服务器不支持事件系统!"); } + this.execute = function execute(exec) { + return function execute() { + try { + exec(arguments[arguments.length - 1]); + } catch (ex) { + console.console('§6插件 §b%s §6处理 §d%s §6事件时发生异常 §4%s'.format(name, this.class2Name(eventCls), ex)); + console.ex(ex); + } + } + } + /** * 添加事件监听 * @param jsp @@ -111,14 +122,7 @@ function EventHandlerDefault() { priority = priority || 'NORMAL'; ignoreCancel = ignoreCancel || false; // noinspection JSUnusedGlobalSymbols - var listener = this.register(eventCls, function execute() { - try { - exec(arguments[arguments.length -1 ]); - } catch (ex) { - console.console('§6插件 §b%s §6处理 §d%s §6事件时发生异常 §4%s'.format(name, this.class2Name(eventCls), ex)); - console.ex(ex); - } - }.bind(this), priority, ignoreCancel); + var listener = this.register(eventCls, this.execute(exec), priority, ignoreCancel); var listenerMap = this.listenerMap; // 添加到缓存 用于关闭插件的时候关闭事件 if (!listenerMap[name]) listenerMap[name] = []; @@ -137,7 +141,7 @@ function EventHandlerDefault() { return off; } } -var EventHandler = Object.assign({}, new EventHandlerDefault(), requireInternal('event')); +var EventHandler = Object.assign(new EventHandlerDefault(), requireInternal('event')); // 映射事件名称 console.info('%s 事件映射完毕 共计 %s 个事件!'.format(DetectServerType, EventHandler.mapEventName().toFixed(0))); module.exports = { @@ -145,7 +149,7 @@ module.exports = { disable: function (jsp) { var jspl = EventHandler.listenerMap[jsp.description.name]; if (jspl) { - jspl.forEach(function (t) t.off.bind(EventHandler)()); + jspl.forEach(function (t) t.off.call(EventHandler)); delete EventHandler.listenerMap[jsp.description.name]; } }