fixed events so that listeners can be removed
This commit is contained in:
parent
1c041d73da
commit
a4ebb4788f
1 changed files with 22 additions and 14 deletions
|
@ -4,10 +4,17 @@ var global = this;
|
||||||
//
|
//
|
||||||
// The following code will print a message on screen every time a block is broken in the game
|
// The following code will print a message on screen every time a block is broken in the game
|
||||||
//
|
//
|
||||||
// bukkit.on('block.BlockBreakEvent',function(evt){
|
// bukkit.on("block.BlockBreakEvent", function(listener, evt){
|
||||||
// print (evt.player.name + " broke a block!");
|
// print (evt.player.name + " broke a block!");
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
|
// To handle an event only once and unregister from further events...
|
||||||
|
//
|
||||||
|
// bukk.on("block.BlockBreakEvent", function(listener, evt){
|
||||||
|
// print (evt.player.name + " broke a block!");
|
||||||
|
// evt.handlers.unregister(listener);
|
||||||
|
// });
|
||||||
|
//
|
||||||
var bukkit = bukkit || {
|
var bukkit = bukkit || {
|
||||||
//
|
//
|
||||||
// handle events in Minecraft
|
// handle events in Minecraft
|
||||||
|
@ -33,9 +40,11 @@ var bukkit = bukkit || {
|
||||||
}
|
}
|
||||||
var _event = org.bukkit.event;
|
var _event = org.bukkit.event;
|
||||||
var _plugin = org.bukkit.plugin;
|
var _plugin = org.bukkit.plugin;
|
||||||
|
//
|
||||||
|
// can't have objects that implement multiple interface in javax.scripts.*
|
||||||
|
//
|
||||||
var theListener = new _event.Listener(){};
|
var theListener = new _event.Listener(){};
|
||||||
|
|
||||||
//
|
|
||||||
var _on = function(eventType, handler, priority)
|
var _on = function(eventType, handler, priority)
|
||||||
{
|
{
|
||||||
if (typeof priority == "undefined"){
|
if (typeof priority == "undefined"){
|
||||||
|
@ -51,18 +60,17 @@ var bukkit = bukkit || {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var handlerList = eventType.getHandlerList();
|
var handlerList = eventType.getHandlerList();
|
||||||
var handlerWrapper = {
|
var listener = {};
|
||||||
execute: function(l,e){
|
var eventExecutor = new _plugin.EventExecutor(){
|
||||||
// drop listener
|
execute: function(l,e){
|
||||||
handler(e);
|
handler(listener.reg,e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var registeredListener = new _plugin.RegisteredListener(theListener,
|
listener.reg = new _plugin.RegisteredListener(
|
||||||
handlerWrapper,
|
theListener,eventExecutor,priority,__plugin,true
|
||||||
priority,
|
)
|
||||||
plugin,
|
handlerList.register(listener.reg);
|
||||||
true);
|
return listener.reg;
|
||||||
handlerList.register(registeredListener);
|
|
||||||
};
|
};
|
||||||
bukkit.on = _on;
|
bukkit.on = _on;
|
||||||
bukkit._eventsLoaded = true;
|
bukkit._eventsLoaded = true;
|
||||||
|
|
Reference in a new issue