Event handling rework. Simplified event handling and unregistering.
This commit is contained in:
parent
9d406dbb44
commit
f82d88cb3f
14 changed files with 108 additions and 78 deletions
|
@ -679,8 +679,7 @@ This method is used to register event listeners.
|
||||||
enclosing quotes).
|
enclosing quotes).
|
||||||
|
|
||||||
* callback - A function which will be called whenever the event
|
* callback - A function which will be called whenever the event
|
||||||
fires. The callback should take 2 parameters, listener (the Bukkit
|
fires. The callback should take a single parameter, event (the event fired).
|
||||||
registered listener for this callback) and event (the event fired).
|
|
||||||
|
|
||||||
* priority (optional - default: "HIGHEST") - The priority the
|
* priority (optional - default: "HIGHEST") - The priority the
|
||||||
listener/callback takes over other listeners to the same
|
listener/callback takes over other listeners to the same
|
||||||
|
@ -690,16 +689,14 @@ This method is used to register event listeners.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
An org.bukkit.plugin.RegisteredListener object which can be used to
|
An object which can be used to unregister the listener.
|
||||||
unregister the listener. This same object is passed to the callback
|
|
||||||
function each time the event is fired.
|
|
||||||
|
|
||||||
#### Example:
|
#### Example:
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
|
events.on( 'block.BlockBreakEvent', function( evt ) {
|
||||||
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
@ -707,24 +704,28 @@ events.on( 'block.BlockBreakEvent', function( listener, evt ) {
|
||||||
To handle an event only once and unregister from further events...
|
To handle an event only once and unregister from further events...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
|
events.on( 'block.BlockBreakEvent', function( evt ) {
|
||||||
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
||||||
evt.handlers.unregister( listener );
|
this.unregister();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
The `this` keyword when used inside the callback function refers to
|
||||||
|
the Listener object created by ScriptCraft. It has a single method
|
||||||
|
`unregister()` which can be used to stop listening. This is the same
|
||||||
|
object which is returned by the `events.on()` function.
|
||||||
|
|
||||||
To unregister a listener *outside* of the listener function...
|
To unregister a listener *outside* of the listener function...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( l, e ) { ... } );
|
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( evt ) { ... } );
|
||||||
...
|
...
|
||||||
var handlers = org.bukkit.event.block.BlockBreakEvent.getHandlerList();
|
myBlockBreakListener.unregister();
|
||||||
handlers.unregister(myBlockBreakListener);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To listen for events using a full class name as the `eventName` parameter...
|
To listen for events using a full class name as the `eventName` parameter...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on( org.bukkit.event.block.BlockBreakEvent, function( listener, evt ) {
|
events.on( org.bukkit.event.block.BlockBreakEvent, function( evt ) {
|
||||||
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
@ -1493,7 +1494,7 @@ Drones can be created in any of the following ways...
|
||||||
block is broken at the block's location you would do so like
|
block is broken at the block's location you would do so like
|
||||||
this...
|
this...
|
||||||
|
|
||||||
events.on('block.BlockBreakEvent',function( listener,event) {
|
events.on('block.BlockBreakEvent',function( event) {
|
||||||
var location = event.block.location;
|
var location = event.block.location;
|
||||||
var drone = new Drone(location);
|
var drone = new Drone(location);
|
||||||
// do more stuff with the drone here...
|
// do more stuff with the drone here...
|
||||||
|
@ -2429,9 +2430,9 @@ parameters...
|
||||||
Package' and 'Previous Package' links to browse).
|
Package' and 'Previous Package' links to browse).
|
||||||
|
|
||||||
2. The event handling function (also sometimes refered to as a
|
2. The event handling function (also sometimes refered to as a
|
||||||
'callback'). In ScriptCraft, this function takes 2 parameters, a
|
'callback'). In ScriptCraft, this function takes a single
|
||||||
listener object and an event object. All of the information about
|
parameter, an event object. All of the information about the event
|
||||||
the event is in the event object.
|
is in the event object.
|
||||||
|
|
||||||
In the example below, if a player joins the server and is an operator,
|
In the example below, if a player joins the server and is an operator,
|
||||||
then the ScriptCraft plugin information will be displayed to that
|
then the ScriptCraft plugin information will be displayed to that
|
||||||
|
@ -2477,7 +2478,7 @@ cleaner and more readable. Similarly where you see a method like
|
||||||
[bksaf]: http://jd.bukkit.org/dev/apidocs/org/bukkit/entity/Player.html#setAllowFlight()
|
[bksaf]: http://jd.bukkit.org/dev/apidocs/org/bukkit/entity/Player.html#setAllowFlight()
|
||||||
[bkapi]: http://jd.bukkit.org/dev/apidocs/
|
[bkapi]: http://jd.bukkit.org/dev/apidocs/
|
||||||
|
|
||||||
events.on( 'player.PlayerJoinEvent', function( listener, event ) {
|
events.on( 'player.PlayerJoinEvent', function( event ) {
|
||||||
if ( event.player.op ) {
|
if ( event.player.op ) {
|
||||||
event.player.sendMessage('Welcome to ' + __plugin);
|
event.player.sendMessage('Welcome to ' + __plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1046,7 +1046,7 @@ following code sends a message to any player who breaks a block in the
|
||||||
game...
|
game...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on('block.BlockBreakEvent', function ( listener, event ) {
|
events.on('block.BlockBreakEvent', function ( event ) {
|
||||||
var breaker = event.player;
|
var breaker = event.player;
|
||||||
breaker.sendMessage('You broke a block');
|
breaker.sendMessage('You broke a block');
|
||||||
} );
|
} );
|
||||||
|
@ -1057,7 +1057,7 @@ want to be called whenever a particular type of event occurs. In the
|
||||||
above code the first parameter `'block.BlockBreakEvent'` is the type
|
above code the first parameter `'block.BlockBreakEvent'` is the type
|
||||||
of event I want to listen for and the second parameter is the function
|
of event I want to listen for and the second parameter is the function
|
||||||
I want to be called when that event occurs. The function I want called
|
I want to be called when that event occurs. The function I want called
|
||||||
in turn takes 2 parameters. The `event` object has all the information
|
in turn takes 1 parameter. The `event` object has all the information
|
||||||
about the event which just occurred. I can tell who broke the block
|
about the event which just occurred. I can tell who broke the block
|
||||||
and send a message to the player. The important thing to note is that
|
and send a message to the player. The important thing to note is that
|
||||||
the function defined above will not be called until a player breaks a
|
the function defined above will not be called until a player breaks a
|
||||||
|
@ -1076,13 +1076,13 @@ It's important to note that when browsing the Bukkit API's
|
||||||
`events.on()` you can listen to such an event using either the fully
|
`events.on()` you can listen to such an event using either the fully
|
||||||
qualified Class name...
|
qualified Class name...
|
||||||
|
|
||||||
events.on(org.bukkit.events.entity.EntityShootBowEvent, function( listener, event) {
|
events.on(org.bukkit.events.entity.EntityShootBowEvent, function( event ) {
|
||||||
...
|
...
|
||||||
});
|
});
|
||||||
|
|
||||||
or an abbreviated name in string form...
|
or an abbreviated name in string form...
|
||||||
|
|
||||||
events.on('entity.EntityShootBowEvent', function( listener, event) {
|
events.on('entity.EntityShootBowEvent', function( event ) {
|
||||||
...
|
...
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1093,7 +1093,7 @@ prepending the 'org.bukkit.events' package.
|
||||||
For custom events (events which aren't in the org.bukkit.event tree)
|
For custom events (events which aren't in the org.bukkit.event tree)
|
||||||
just specify the fully qualified class name instead. E.g. ...
|
just specify the fully qualified class name instead. E.g. ...
|
||||||
|
|
||||||
events.on ( net.yourdomain.events.YourEvent, function(listener, event ) {
|
events.on ( net.yourdomain.events.YourEvent, function( event ) {
|
||||||
...
|
...
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1102,15 +1102,27 @@ just specify the fully qualified class name instead. E.g. ...
|
||||||
If you want an event handler to only execute once, you can remove the handler like this...
|
If you want an event handler to only execute once, you can remove the handler like this...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on('block.BlockBreakEvent', function( listener, evt ) {
|
events.on('block.BlockBreakEvent', function( evt ) {
|
||||||
var breaker = evt.player;
|
var breaker = evt.player;
|
||||||
breaker.sendMessage('You broke a block');
|
breaker.sendMessage('You broke a block');
|
||||||
evt.handlers.unregister( listener );
|
this.unregister();
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
|
||||||
The `evt.handlers.unregister( listener );` statement will remove this
|
The `this.unregister();` statement will remove this function from the
|
||||||
function from the list of listeners for this event.
|
list of listeners for the event. The `this` keyword when used inside
|
||||||
|
an event handling function refers to a Listener object provided by
|
||||||
|
ScriptCraft, it has a single method `unregister()` which can be used
|
||||||
|
to stop listening for events.
|
||||||
|
|
||||||
|
To unregister a listener *outside* of the listener function...
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( evt ) { ... } );
|
||||||
|
...
|
||||||
|
myBlockBreakListener.unregister();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Keeping Score - Lookup tables in Javascript
|
## Keeping Score - Lookup tables in Javascript
|
||||||
|
|
||||||
|
@ -1221,10 +1233,10 @@ keep a count of how many blocks each player has broken ...
|
||||||
```javascript
|
```javascript
|
||||||
var breaks = {};
|
var breaks = {};
|
||||||
// every time a player joins the game reset their block-break-count to 0
|
// every time a player joins the game reset their block-break-count to 0
|
||||||
events.on('player.PlayerJoinEvent', function(listener, event){
|
events.on('player.PlayerJoinEvent', function( event ) {
|
||||||
breaks[event.player] = 0;
|
breaks[event.player] = 0;
|
||||||
});
|
});
|
||||||
events.on('block.BlockBreakEvent', function(listener, event){
|
events.on('block.BlockBreakEvent', function( event ) {
|
||||||
var breaker = event.player;
|
var breaker = event.player;
|
||||||
var breakCount = breaks[breaker.name];
|
var breakCount = breaks[breaker.name];
|
||||||
breakCount++; // increment the count.
|
breakCount++; // increment the count.
|
||||||
|
|
34
src/docs/templates/ypgpm.md
vendored
34
src/docs/templates/ypgpm.md
vendored
|
@ -1010,7 +1010,7 @@ following code sends a message to any player who breaks a block in the
|
||||||
game...
|
game...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on('block.BlockBreakEvent', function ( listener, event ) {
|
events.on('block.BlockBreakEvent', function ( event ) {
|
||||||
var breaker = event.player;
|
var breaker = event.player;
|
||||||
breaker.sendMessage('You broke a block');
|
breaker.sendMessage('You broke a block');
|
||||||
} );
|
} );
|
||||||
|
@ -1021,7 +1021,7 @@ want to be called whenever a particular type of event occurs. In the
|
||||||
above code the first parameter `'block.BlockBreakEvent'` is the type
|
above code the first parameter `'block.BlockBreakEvent'` is the type
|
||||||
of event I want to listen for and the second parameter is the function
|
of event I want to listen for and the second parameter is the function
|
||||||
I want to be called when that event occurs. The function I want called
|
I want to be called when that event occurs. The function I want called
|
||||||
in turn takes 2 parameters. The `event` object has all the information
|
in turn takes 1 parameter. The `event` object has all the information
|
||||||
about the event which just occurred. I can tell who broke the block
|
about the event which just occurred. I can tell who broke the block
|
||||||
and send a message to the player. The important thing to note is that
|
and send a message to the player. The important thing to note is that
|
||||||
the function defined above will not be called until a player breaks a
|
the function defined above will not be called until a player breaks a
|
||||||
|
@ -1040,13 +1040,13 @@ It's important to note that when browsing the Bukkit API's
|
||||||
`events.on()` you can listen to such an event using either the fully
|
`events.on()` you can listen to such an event using either the fully
|
||||||
qualified Class name...
|
qualified Class name...
|
||||||
|
|
||||||
events.on(org.bukkit.events.entity.EntityShootBowEvent, function( listener, event) {
|
events.on(org.bukkit.events.entity.EntityShootBowEvent, function( event ) {
|
||||||
...
|
...
|
||||||
});
|
});
|
||||||
|
|
||||||
or an abbreviated name in string form...
|
or an abbreviated name in string form...
|
||||||
|
|
||||||
events.on('entity.EntityShootBowEvent', function( listener, event) {
|
events.on('entity.EntityShootBowEvent', function( event ) {
|
||||||
...
|
...
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1057,7 +1057,7 @@ prepending the 'org.bukkit.events' package.
|
||||||
For custom events (events which aren't in the org.bukkit.event tree)
|
For custom events (events which aren't in the org.bukkit.event tree)
|
||||||
just specify the fully qualified class name instead. E.g. ...
|
just specify the fully qualified class name instead. E.g. ...
|
||||||
|
|
||||||
events.on ( net.yourdomain.events.YourEvent, function(listener, event ) {
|
events.on ( net.yourdomain.events.YourEvent, function( event ) {
|
||||||
...
|
...
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1066,15 +1066,27 @@ just specify the fully qualified class name instead. E.g. ...
|
||||||
If you want an event handler to only execute once, you can remove the handler like this...
|
If you want an event handler to only execute once, you can remove the handler like this...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on('block.BlockBreakEvent', function( listener, evt ) {
|
events.on('block.BlockBreakEvent', function( evt ) {
|
||||||
var breaker = evt.player;
|
var breaker = evt.player;
|
||||||
breaker.sendMessage('You broke a block');
|
breaker.sendMessage('You broke a block');
|
||||||
evt.handlers.unregister( listener );
|
this.unregister();
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
|
||||||
The `evt.handlers.unregister( listener );` statement will remove this
|
The `this.unregister();` statement will remove this function from the
|
||||||
function from the list of listeners for this event.
|
list of listeners for the event. The `this` keyword when used inside
|
||||||
|
an event handling function refers to a Listener object provided by
|
||||||
|
ScriptCraft, it has a single method `unregister()` which can be used
|
||||||
|
to stop listening for events.
|
||||||
|
|
||||||
|
To unregister a listener *outside* of the listener function...
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( evt ) { ... } );
|
||||||
|
...
|
||||||
|
myBlockBreakListener.unregister();
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Keeping Score - Lookup tables in Javascript
|
## Keeping Score - Lookup tables in Javascript
|
||||||
|
|
||||||
|
@ -1185,10 +1197,10 @@ keep a count of how many blocks each player has broken ...
|
||||||
```javascript
|
```javascript
|
||||||
var breaks = {};
|
var breaks = {};
|
||||||
// every time a player joins the game reset their block-break-count to 0
|
// every time a player joins the game reset their block-break-count to 0
|
||||||
events.on('player.PlayerJoinEvent', function(listener, event){
|
events.on('player.PlayerJoinEvent', function( event ) {
|
||||||
breaks[event.player] = 0;
|
breaks[event.player] = 0;
|
||||||
});
|
});
|
||||||
events.on('block.BlockBreakEvent', function(listener, event){
|
events.on('block.BlockBreakEvent', function( event ) {
|
||||||
var breaker = event.player;
|
var breaker = event.player;
|
||||||
var breakCount = breaks[breaker.name];
|
var breakCount = breaks[breaker.name];
|
||||||
breakCount++; // increment the count.
|
breakCount++; // increment the count.
|
||||||
|
|
|
@ -27,8 +27,7 @@ This method is used to register event listeners.
|
||||||
enclosing quotes).
|
enclosing quotes).
|
||||||
|
|
||||||
* callback - A function which will be called whenever the event
|
* callback - A function which will be called whenever the event
|
||||||
fires. The callback should take 2 parameters, listener (the Bukkit
|
fires. The callback should take a single parameter, event (the event fired).
|
||||||
registered listener for this callback) and event (the event fired).
|
|
||||||
|
|
||||||
* priority (optional - default: "HIGHEST") - The priority the
|
* priority (optional - default: "HIGHEST") - The priority the
|
||||||
listener/callback takes over other listeners to the same
|
listener/callback takes over other listeners to the same
|
||||||
|
@ -38,16 +37,14 @@ This method is used to register event listeners.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
|
|
||||||
An org.bukkit.plugin.RegisteredListener object which can be used to
|
An object which can be used to unregister the listener.
|
||||||
unregister the listener. This same object is passed to the callback
|
|
||||||
function each time the event is fired.
|
|
||||||
|
|
||||||
#### Example:
|
#### Example:
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
|
events.on( 'block.BlockBreakEvent', function( evt ) {
|
||||||
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
@ -55,24 +52,28 @@ events.on( 'block.BlockBreakEvent', function( listener, evt ) {
|
||||||
To handle an event only once and unregister from further events...
|
To handle an event only once and unregister from further events...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
|
events.on( 'block.BlockBreakEvent', function( evt ) {
|
||||||
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
||||||
evt.handlers.unregister( listener );
|
this.unregister();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
The `this` keyword when used inside the callback function refers to
|
||||||
|
the Listener object created by ScriptCraft. It has a single method
|
||||||
|
`unregister()` which can be used to stop listening. This is the same
|
||||||
|
object which is returned by the `events.on()` function.
|
||||||
|
|
||||||
To unregister a listener *outside* of the listener function...
|
To unregister a listener *outside* of the listener function...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( l, e ) { ... } );
|
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( evt ) { ... } );
|
||||||
...
|
...
|
||||||
var handlers = org.bukkit.event.block.BlockBreakEvent.getHandlerList();
|
myBlockBreakListener.unregister();
|
||||||
handlers.unregister(myBlockBreakListener);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To listen for events using a full class name as the `eventName` parameter...
|
To listen for events using a full class name as the `eventName` parameter...
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
events.on( org.bukkit.event.block.BlockBreakEvent, function( listener, evt ) {
|
events.on( org.bukkit.event.block.BlockBreakEvent, function( evt ) {
|
||||||
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
evt.player.sendMessage( evt.player.name + ' broke a block!');
|
||||||
} );
|
} );
|
||||||
```
|
```
|
||||||
|
@ -118,9 +119,11 @@ exports.on = function(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handlerList = eventType.getHandlerList( );
|
handlerList = eventType.getHandlerList( );
|
||||||
|
|
||||||
|
var result = { };
|
||||||
eventExecutor = new bkEventExecutor( ) {
|
eventExecutor = new bkEventExecutor( ) {
|
||||||
execute: function( l, e ) {
|
execute: function( l, evt ) {
|
||||||
handler( listener.reg, e );
|
handler.call( result, evt );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
|
@ -133,5 +136,8 @@ exports.on = function(
|
||||||
*/
|
*/
|
||||||
listener.reg = new bkRegisteredListener( __plugin, eventExecutor, priority, __plugin, true );
|
listener.reg = new bkRegisteredListener( __plugin, eventExecutor, priority, __plugin, true );
|
||||||
handlerList.register( listener.reg );
|
handlerList.register( listener.reg );
|
||||||
return listener.reg;
|
result.unregister = function(){
|
||||||
|
handlerList.unregister( listener.reg );
|
||||||
|
};
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
|
@ -617,7 +617,7 @@ function __onEnable ( __engine, __plugin, __script )
|
||||||
global.plugin = plugins.plugin;
|
global.plugin = plugins.plugin;
|
||||||
|
|
||||||
var events = require('events');
|
var events = require('events');
|
||||||
events.on( 'server.PluginDisableEvent', function( l, e ) {
|
events.on( 'server.PluginDisableEvent', function( evt ) {
|
||||||
// save config
|
// save config
|
||||||
_save( global.config, new File( jsPluginsRootDir, 'data/global-config.json' ) );
|
_save( global.config, new File( jsPluginsRootDir, 'data/global-config.json' ) );
|
||||||
|
|
||||||
|
|
|
@ -184,7 +184,7 @@ signs.menu = function( /* String */ label, /* Array */ options, /* Function */ c
|
||||||
//
|
//
|
||||||
// update it every time player interacts with it.
|
// update it every time player interacts with it.
|
||||||
//
|
//
|
||||||
events.on( 'player.PlayerInteractEvent', function( listener, event ) {
|
events.on( 'player.PlayerInteractEvent', function( event ) {
|
||||||
/*
|
/*
|
||||||
look up our list of menu signs. If there's a matching location and there's
|
look up our list of menu signs. If there's a matching location and there's
|
||||||
a sign, then update it.
|
a sign, then update it.
|
||||||
|
|
|
@ -223,7 +223,7 @@ var _intercept = function( msg, invoker, exec ) {
|
||||||
Intercept all command processing and replace with aliased commands if the
|
Intercept all command processing and replace with aliased commands if the
|
||||||
command about to be issued matches an alias.
|
command about to be issued matches an alias.
|
||||||
*/
|
*/
|
||||||
events.on( 'player.PlayerCommandPreprocessEvent', function( listener, evt ) {
|
events.on( 'player.PlayerCommandPreprocessEvent', function( evt ) {
|
||||||
var invoker = evt.player;
|
var invoker = evt.player;
|
||||||
var exec = function( cmd ) {
|
var exec = function( cmd ) {
|
||||||
invoker.performCommand(cmd);
|
invoker.performCommand(cmd);
|
||||||
|
@ -237,7 +237,7 @@ events.on( 'player.PlayerCommandPreprocessEvent', function( listener, evt ) {
|
||||||
command('void',function( ) {
|
command('void',function( ) {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
events.on( 'server.ServerCommandEvent', function( listener, evt ) {
|
events.on( 'server.ServerCommandEvent', function( evt ) {
|
||||||
var invoker = evt.sender;
|
var invoker = evt.sender;
|
||||||
var exec = function( cmd ) {
|
var exec = function( cmd ) {
|
||||||
invoker.server.dispatchCommand( invoker, cmd);
|
invoker.server.dispatchCommand( invoker, cmd);
|
||||||
|
|
|
@ -79,7 +79,7 @@ arrows.sign = function( cmdSender ) {
|
||||||
/*
|
/*
|
||||||
event handler called when a projectile hits something
|
event handler called when a projectile hits something
|
||||||
*/
|
*/
|
||||||
var _onArrowHit = function( listener, event ) {
|
var _onArrowHit = function( event ) {
|
||||||
var projectile = event.entity,
|
var projectile = event.entity,
|
||||||
world = projectile.world,
|
world = projectile.world,
|
||||||
shooter = projectile.shooter,
|
shooter = projectile.shooter,
|
||||||
|
|
|
@ -158,7 +158,7 @@ var classroom = plugin('classroom', {
|
||||||
|
|
||||||
exports.classroom = classroom;
|
exports.classroom = classroom;
|
||||||
|
|
||||||
events.on( 'player.PlayerJoinEvent', function( listener, event ) {
|
events.on( 'player.PlayerJoinEvent', function( event ) {
|
||||||
if ( _store.enableScripting ) {
|
if ( _store.enableScripting ) {
|
||||||
grantScripting(event.player);
|
grantScripting(event.player);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,8 @@ exports.commando = function( name, func, options, intercepts ) {
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
events.on( 'player.PlayerCommandPreprocessEvent', function( l, e ) {
|
events.on( 'player.PlayerCommandPreprocessEvent', function( evt ) {
|
||||||
var msg = '' + e.message;
|
var msg = '' + evt.message;
|
||||||
var parts = msg.match( /^\/([^\s]+)/ );
|
var parts = msg.match( /^\/([^\s]+)/ );
|
||||||
if ( !parts ) {
|
if ( !parts ) {
|
||||||
return;
|
return;
|
||||||
|
@ -95,11 +95,11 @@ events.on( 'player.PlayerCommandPreprocessEvent', function( l, e ) {
|
||||||
}
|
}
|
||||||
var command = parts[1];
|
var command = parts[1];
|
||||||
if ( commands[command] ) {
|
if ( commands[command] ) {
|
||||||
e.message = '/jsp ' + msg.replace( /^\//, '' );
|
evt.message = '/jsp ' + msg.replace( /^\//, '' );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
events.on( 'server.ServerCommandEvent', function( l, e ) {
|
events.on( 'server.ServerCommandEvent', function( evt ) {
|
||||||
var msg = '' + e.command;
|
var msg = '' + evt.command;
|
||||||
var parts = msg.match( /^\/*([^\s]+)/ );
|
var parts = msg.match( /^\/*([^\s]+)/ );
|
||||||
if ( !parts ) {
|
if ( !parts ) {
|
||||||
return;
|
return;
|
||||||
|
@ -113,6 +113,6 @@ events.on( 'server.ServerCommandEvent', function( l, e ) {
|
||||||
if ( config.verbose ) {
|
if ( config.verbose ) {
|
||||||
console.log( 'Redirecting to : %s', newCmd );
|
console.log( 'Redirecting to : %s', newCmd );
|
||||||
}
|
}
|
||||||
e.command = newCmd;
|
evt.command = newCmd;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -118,7 +118,7 @@ Drones can be created in any of the following ways...
|
||||||
block is broken at the block's location you would do so like
|
block is broken at the block's location you would do so like
|
||||||
this...
|
this...
|
||||||
|
|
||||||
events.on('block.BlockBreakEvent',function( listener,event) {
|
events.on('block.BlockBreakEvent',function( event) {
|
||||||
var location = event.block.location;
|
var location = event.block.location;
|
||||||
var drone = new Drone(location);
|
var drone = new Drone(location);
|
||||||
// do more stuff with the drone here...
|
// do more stuff with the drone here...
|
||||||
|
|
|
@ -31,9 +31,9 @@ parameters...
|
||||||
Package' and 'Previous Package' links to browse).
|
Package' and 'Previous Package' links to browse).
|
||||||
|
|
||||||
2. The event handling function (also sometimes refered to as a
|
2. The event handling function (also sometimes refered to as a
|
||||||
'callback'). In ScriptCraft, this function takes 2 parameters, a
|
'callback'). In ScriptCraft, this function takes a single
|
||||||
listener object and an event object. All of the information about
|
parameter, an event object. All of the information about the event
|
||||||
the event is in the event object.
|
is in the event object.
|
||||||
|
|
||||||
In the example below, if a player joins the server and is an operator,
|
In the example below, if a player joins the server and is an operator,
|
||||||
then the ScriptCraft plugin information will be displayed to that
|
then the ScriptCraft plugin information will be displayed to that
|
||||||
|
@ -79,14 +79,14 @@ cleaner and more readable. Similarly where you see a method like
|
||||||
[bksaf]: http://jd.bukkit.org/dev/apidocs/org/bukkit/entity/Player.html#setAllowFlight()
|
[bksaf]: http://jd.bukkit.org/dev/apidocs/org/bukkit/entity/Player.html#setAllowFlight()
|
||||||
[bkapi]: http://jd.bukkit.org/dev/apidocs/
|
[bkapi]: http://jd.bukkit.org/dev/apidocs/
|
||||||
|
|
||||||
events.on( 'player.PlayerJoinEvent', function( listener, event ) {
|
events.on( 'player.PlayerJoinEvent', function( event ) {
|
||||||
if ( event.player.op ) {
|
if ( event.player.op ) {
|
||||||
event.player.sendMessage('Welcome to ' + __plugin);
|
event.player.sendMessage('Welcome to ' + __plugin);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
***/
|
***/
|
||||||
events.on( 'player.PlayerJoinEvent', function( listener, event ) {
|
events.on( 'player.PlayerJoinEvent', function( event ) {
|
||||||
if ( event.player.op ) {
|
if ( event.player.op ) {
|
||||||
event.player.sendMessage( 'Welcome to ' + __plugin );
|
event.player.sendMessage( 'Welcome to ' + __plugin );
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,8 +112,7 @@ var _endGame = function( gameState ) {
|
||||||
player.sendMessage( scores );
|
player.sendMessage( scores );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handlerList = bkEntityDamageByEntityEvent.getHandlerList();
|
gameState.listener.unregister();
|
||||||
handlerList.unregister( gameState.listener );
|
|
||||||
gameState.inProgress = false;
|
gameState.inProgress = false;
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
|
@ -177,7 +176,7 @@ var createGame = function( duration, teams ) {
|
||||||
/*
|
/*
|
||||||
this function is called every time a player is damaged by another entity/player
|
this function is called every time a player is damaged by another entity/player
|
||||||
*/
|
*/
|
||||||
var _onSnowballHit = function( l, event ) {
|
var _onSnowballHit = function( event ) {
|
||||||
var snowball = event.damager;
|
var snowball = event.damager;
|
||||||
if ( !snowball || !( snowball instanceof bkSnowball ) ) {
|
if ( !snowball || !( snowball instanceof bkSnowball ) ) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -53,7 +53,7 @@ var store = {},
|
||||||
};
|
};
|
||||||
var scoreboard = require('minigames/scoreboard')(scoreboardConfig);
|
var scoreboard = require('minigames/scoreboard')(scoreboardConfig);
|
||||||
|
|
||||||
var _onPlayerInteract = function( listener, event ) {
|
var _onPlayerInteract = function( event ) {
|
||||||
var player = event.player,
|
var player = event.player,
|
||||||
clickedEntity = event.rightClicked,
|
clickedEntity = event.rightClicked,
|
||||||
loc = clickedEntity.location;
|
loc = clickedEntity.location;
|
||||||
|
@ -77,10 +77,10 @@ var _onPlayerInteract = function( listener, event ) {
|
||||||
}, 200 );
|
}, 200 );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var _onPlayerQuit = function( listener, event ) {
|
var _onPlayerQuit = function( event ) {
|
||||||
_removePlayer( event.player );
|
_removePlayer( event.player );
|
||||||
};
|
};
|
||||||
var _onPlayerJoin = function( listener, event ) {
|
var _onPlayerJoin = function( event ) {
|
||||||
var gamePlayer = store[event.player.name];
|
var gamePlayer = store[event.player.name];
|
||||||
if ( gamePlayer ) {
|
if ( gamePlayer ) {
|
||||||
_addPlayer( event.player, gamePlayer.score );
|
_addPlayer( event.player, gamePlayer.score );
|
||||||
|
|
Reference in a new issue