diff --git a/src/main/resources/internal/bukkit/event.js b/src/main/resources/internal/bukkit/event.js index b01ab9f..0d6a1c6 100644 --- a/src/main/resources/internal/bukkit/event.js +++ b/src/main/resources/internal/bukkit/event.js @@ -77,7 +77,7 @@ function isVaildEvent(clz) { * @param jsp * @param event * @param exec {function} - * @param priority + * @param priority [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR] * @param ignoreCancel */ function listen(jsp, event, exec, priority, ignoreCancel) { @@ -94,7 +94,8 @@ function listen(jsp, event, exec, priority, ignoreCancel) { } } if (typeof priority === 'boolean') { - ignoreCancel = priority + ignoreCancel = priority; + priority = 'NORMAL'; } priority = priority || 'NORMAL'; ignoreCancel = ignoreCancel || false; @@ -113,7 +114,7 @@ function listen(jsp, event, exec, priority, ignoreCancel) { listener, EventPriority[priority], new EventExecutor({ - execute: function (listener, event) { + execute: function execute(listener, event) { try { exec(event); } catch (ex) { diff --git a/src/main/resources/internal/sponge/event.js b/src/main/resources/internal/sponge/event.js index 2345fe1..a3d545a 100644 --- a/src/main/resources/internal/sponge/event.js +++ b/src/main/resources/internal/sponge/event.js @@ -8,6 +8,7 @@ var Thread = Java.type("java.lang.Thread"); var EventListener = Java.type("org.spongepowered.api.event.EventListener"); var Modifier = Java.type("java.lang.reflect.Modifier"); var Event = Java.type("org.spongepowered.api.event.Event"); +var Order = Java.type("org.spongepowered.api.event.Order"); var plugin = require('./server').plugin.self; @@ -76,7 +77,7 @@ function isVaildEvent(clz) { * @param jsp * @param event * @param exec {function} - * @param priority + * @param priority [PRE,AFTER_PRE,FIRST,EARLY,DEFAULT,LATE,LAST,BEFORE_POST,POST] * @param ignoreCancel */ function listen(jsp, event, exec, priority, ignoreCancel) { @@ -85,15 +86,21 @@ function listen(jsp, event, exec, priority, ignoreCancel) { var eventCls = name2Class(event); if (typeof priority === 'boolean') { ignoreCancel = priority + priority = 'DEFAULT' } - priority = priority || 'NORMAL'; + priority = priority || 'DEFAULT'; ignoreCancel = ignoreCancel || false; var listener = new EventListener({ handle: function handle(event) { - exec(event); + try { + exec(event); + } catch (ex) { + console.console('§6插件 §b%s §6处理 §d%s §6事件时发生异常 §4%s'.format(name, event.class.simpleName, ex)); + console.ex(ex); + } } }); - Sponge.getEventManager().registerListener(plugin, eventCls, listener) + Sponge.getEventManager().registerListener(plugin, eventCls, Order[priority], listener) // 添加到缓存 用于关闭插件的时候关闭事件 if (!listenerMap[name]) listenerMap[name] = []; var listeners = listenerMap[name];