This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/js/lib/events-canary.js
walterhiggins 19162c3688 First phase of transition from Bukkit to Canary.
Some of the plugins are not yet supported.
If you're feeling brave you can build from source using ant.
2014-09-29 23:42:41 +01:00

46 lines
1.5 KiB
JavaScript

var cmPriority = Packages.net.canarymod.plugin.Priority,
cmCanary = Packages.net.canarymod.Canary,
cmDispatcher = Packages.net.canarymod.hook.Dispatcher,
cmRegisteredPluginListener = Packages.net.canarymod.plugin.RegisteredPluginListener,
cmPluginListener = Packages.net.canarymod.plugin.PluginListener;
var cmHookExecutor = cmCanary.hooks();
exports.on = function(
/* Java Class */
eventType,
/* function( registeredListener, event) */
handler,
/* (optional) String (CRITICAL, HIGH, NORMAL, LOW, PASSIVE), */
priority ) {
var handlerList,
regd,
eventExecutor;
if ( typeof priority == 'undefined' ) {
priority = cmPriority.NORMAL;
} else {
priority = cmPriority[priority.toUpperCase().trim()];
}
var result = { };
eventExecutor = new cmDispatcher( {
execute: function (l, evt) {
handler.call(result, evt );
}
});
/*
wph 20130222 issue #64 bad interaction with Essentials plugin
if another plugin tries to unregister a Listener (not a Plugin or a RegisteredListener)
then BOOM! the other plugin will throw an error because Rhino can't coerce an
equals() method from an Interface.
The workaround is to make the ScriptCraftPlugin java class a Listener.
Should only unregister() registered plugins in ScriptCraft js code.
*/
regd = new cmPluginListener({});
cmHookExecutor.registerHook(regd, __plugin, eventType.class, eventExecutor, priority);
result.unregister = function(){
cmHookExecutor.unregisterPluginListener(regd);
};
return result;
};