var global = this;
/************************************************************************
events Module
=============
The Events module provides a thin wrapper around Bukkit's
Event-handling API.  Bukkit's Events API makes use of Java Annotations
which are not available in Javascript, so this module provides a
simple way to listen to minecraft events in javascript.

events.on() static method
=========================
This method is used to register event listeners. 

Parameters
----------

 * eventName - A string or java class. If a string is supplied it must
   be part of the Bukkit event class name.  See [Bukkit API][buk] for
   details of the many bukkit event types. When a string is supplied
   there is no need to provide the full class name - you should omit
   the 'org.bukkit.event' prefix. e.g. if the string
   "block.BlockBreakEvent" is supplied then it's converted to the
   org.bukkit.event.block.BlockBreakEvent class .
 
   If a java class is provided (say in the case where you've defined
   your own custom event) then provide the full class name (without
   enclosing quotes).

 * callback - A function which will be called whenever the event
   fires. The callback should take 2 parameters, listener (the Bukkit
   registered listener for this callback) and event (the event fired).

 * priority (optional - default: "HIGHEST") - The priority the
   listener/callback takes over other listeners to the same
   event. Possible values are "HIGH", "HIGHEST", "LOW", "LOWEST",
   "NORMAL", "MONITOR". For an explanation of what the different
   priorities mean refer to bukkit's [Event API Reference][buk2].

Returns
-------
An org.bukkit.plugin.RegisteredListener object which can be used to
unregister the listener. This same object is passed to the callback
function each time the event is fired.

Example:
------
The following code will print a message on screen every time a block is broken in the game

    events.on("block.BlockBreakEvent", function(listener, evt){ 
        echo (evt.player.name + " broke a block!");
    });

To handle an event only once and unregister from further events...
    
    events.on("block.BlockBreakEvent", function(listener, evt){ 
        print (evt.player.name + " broke a block!");
        evt.handlers.unregister(listener);
    });

To unregister a listener *outside* of the listener function...

    var myBlockBreakListener = events.on("block.BlockBreakEvent",function(l,e){ ... });
    ...
    var handlers = org.bukkit.event.block.BlockBreakEvent.getHandlerList();
    handlers.unregister(myBlockBreakListener);

[buk2]: http://wiki.bukkit.org/Event_API_Reference
[buk]: http://jd.bukkit.org/dev/apidocs/index.html?org/bukkit/event/Event.html

***/
 
var events = events || {
    //
    // handle events in Minecraft
    // --------------------------
    // eventType can be a string (assumed to be a sub package of org.bukkit.event - e.g. 
    // if the string "block.BlockBreakEvent" is supplied then it's converted to the 
    // org.bukkit.event.block.BlockBreakEvent class . For custom event classes, just 
    // supply the custom event class e.g.
    // events.on(net.yourdomain.events.YourCustomEvent,function(l,e){ ... });
    //
    on: function(
        /* String or java Class */ eventType, 
        /* function( registeredListener, event) */ handler, 
        /* (optional) String (HIGH, HIGHEST, LOW, LOWEST, NORMAL, MONITOR), */ priority
    ){}
};
//
// private implementation from here on in...
//
(function(){
    if (events._eventsLoaded){
        return;
    }
    var _event = org.bukkit.event;
    var _plugin = org.bukkit.plugin;

    var _on = function(eventType, handler, priority)
    {
        if (typeof priority == "undefined"){
            priority = _event.EventPriority.HIGHEST;
        }else{
            priority = _event.EventPriority[priority];
        }
        if (typeof eventType == "string"){
            var subPkgs = eventType.split('.');
            eventType = _event[subPkgs[0]];
            for (var i = 1;i < subPkgs.length; i++){
                eventType = eventType[subPkgs[i]];
            }
        }
        var handlerList = eventType.getHandlerList();
        var listener = {};
        var eventExecutor = new _plugin.EventExecutor(){
            execute: function(l,e){
                handler(listener.reg,e);
            } 
        };
        listener.reg = new _plugin.RegisteredListener(
            /* 
               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.
            */
            __plugin
            ,eventExecutor
            ,priority
            ,__plugin
            ,true
        )
        handlerList.register(listener.reg);
        return listener.reg;
    };
    events.on = _on;
    events._eventsLoaded = true;
}());

@@ -1,23 +1,4 @@
-var global = this;%0A
 /***
@@ -3474,16 +3474,22 @@
 unction(
+events
 )%7B%0A    i
@@ -3544,18 +3544,19 @@
     var 
-_e
+bkE
 vent = o
@@ -3580,23 +3580,86 @@
     var 
-_plugin
+bkEvtExecutor = org.bukkit.plugin.EventExecutor;%0A    var bkRegListener
  = org.b
@@ -3670,16 +3670,35 @@
 t.plugin
+.RegisteredListener
 ;%0A%0A    v
@@ -3811,34 +3811,35 @@
      priority = 
-_e
+bkE
 vent.EventPriori
@@ -3888,18 +3888,19 @@
 ority = 
-_e
+bkE
 vent.Eve
@@ -4046,18 +4046,19 @@
 tType = 
-_e
+bkE
 vent%5Bsub
@@ -4312,20 +4312,12 @@
 new 
-_plugin.Even
+bkEv
 tExe
@@ -4440,75 +4440,12 @@
     
-listener.reg = new _plugin.RegisteredListener(%0A            /* %0A    
+/* %0A
     
@@ -4509,28 +4509,24 @@
 ials plugin%0A
-    
            i
@@ -4623,20 +4623,16 @@
         
-  
-  
 then BOO
@@ -4701,20 +4701,16 @@
 erce an%0A
-    
         
@@ -4758,20 +4758,16 @@
         
-    
 The work
@@ -4840,20 +4840,16 @@
         
-  
-  
 Should o
@@ -4916,20 +4916,16 @@
         
-    
 */%0A     
@@ -4931,119 +4931,93 @@
     
-    __plugin%0A            ,eventExecutor%0A            ,priority%0A            ,__plugin%0A            ,true%0A        )
+listener.reg = new bkRegListener( __plugin, eventExecutor, priority, __plugin, true);
 %0A   
@@ -5149,12 +5149,18 @@
 true;%0A%7D(
+events
 ));%0A

tidy up variable names