further syntax-highlighting and ignore netbeans folder.

This commit is contained in:
walterhiggins 2014-02-04 21:49:12 +00:00
parent f1925efd87
commit 39b459ab7f
6 changed files with 116 additions and 94 deletions

2
.gitignore vendored
View file

@ -13,3 +13,5 @@ target
build.local.properties
/src/main/javascript/lib/.#tabcomplete.js
/src/main/javascript/plugins/.#example-1.js
/nbproject/private/private.xml
/nbproject/project.xml

View file

@ -693,29 +693,36 @@ function each time the event is fired.
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){
evt.player.sendMessage( evt.player.name + ' broke a block!');
});
```javascript
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
evt.player.sendMessage( evt.player.name + ' broke a block!');
} );
```
To handle an event only once and unregister from further events...
events.on('block.BlockBreakEvent', function(listener, evt){
evt.player.sendMessage( evt.player.name + ' broke a block!');
evt.handlers.unregister(listener);
});
```javascript
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
evt.player.sendMessage( 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);
```javascript
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( l, e ) { ... } );
...
var handlers = org.bukkit.event.block.BlockBreakEvent.getHandlerList();
handlers.unregister(myBlockBreakListener);
```
To listen for events using a full class name as the `eventName` parameter...
events.on(org.bukkit.event.block.BlockBreakEvent, function(listener, evt){
evt.player.sendMessage( evt.player.name + ' broke a block!');
});
```javascript
events.on( org.bukkit.event.block.BlockBreakEvent, function( listener, evt ) {
evt.player.sendMessage( evt.player.name + ' broke a block!');
} );
```
[buk2]: http://wiki.bukkit.org/Event_API_Reference
[buk]: http://jd.bukkit.org/dev/apidocs/index.html?org/bukkit/event/Event.html
@ -949,30 +956,31 @@ an interactive sign.
#### Example: Create a sign which changes the time of day.
##### plugins/signs/time-of-day.js
var utils = require('utils'),
signs = require('signs');
```javascript
var utils = require('utils'),
signs = require('signs');
var onTimeChoice = function(event){
var selectedIndex = event.number;
// convert to Minecraft time 0 = Dawn, 6000 = midday, 12000 = dusk, 18000 = midnight
var time = selectedIndex * 6000;
event.player.location.world.setTime(time);
};
var onTimeChoice = function(event){
var selectedIndex = event.number;
// convert to Minecraft time 0 = Dawn, 6000 = midday, 12000 = dusk, 18000 = midnight
var time = selectedIndex * 6000;
event.player.location.world.setTime(time);
};
// signs.menu returns a function which can be called for one or more signs in the game.
var convertToTimeMenu = signs.menu('Time of Day',
['Dawn', 'Midday', 'Dusk', 'Midnight'],
onTimeChoice);
// signs.menu returns a function which can be called for one or more signs in the game.
var convertToTimeMenu = signs.menu('Time of Day',
['Dawn', 'Midday', 'Dusk', 'Midnight'],
onTimeChoice);
exports.time_sign = function( player ){
var sign = signs.getTargetedBy(player);
if (!sign){
throw new Error('You must look at a sign');
}
convertToTimeMenu(sign);
};
exports.time_sign = function( player ){
var sign = signs.getTargetedBy(player);
if ( !sign ) {
throw new Error('You must look at a sign');
}
convertToTimeMenu(sign);
};
```
To use the above function at the in-game prompt, look at an existing
sign and type...
@ -990,13 +998,15 @@ the entity has targeted. It is a utility function for use by plugin authors.
#### Example
var signs = require('signs'),
utils = require('utils');
var player = utils.player('tom1234');
var sign = signs.getTargetedBy( player );
if (!sign){
player.sendMessage('Not looking at a sign');
}
```javascript
var signs = require('signs'),
utils = require('utils');
var player = utils.player('tom1234');
var sign = signs.getTargetedBy( player );
if ( !sign ) {
player.sendMessage('Not looking at a sign');
}
```
[buksign]: http://jd.bukkit.org/dev/apidocs/org/bukkit/block/Sign.html

View file

@ -765,7 +765,7 @@ loop. The following `while` loop counts to 100...
```javascript
var i = 1;
while (i <= 100){
while ( i <= 100 ) {
console.log( i );
i = i + 1;
}
@ -892,12 +892,12 @@ type the following...
```javascript
var myskyscraper = function(floors) {
if (typeof floors == 'undefined'){
var i ;
if ( typeof floors == 'undefined' ) {
floors = 10;
}
this.chkpt('myskyscraper'); // saves the drone position so it can return there later
for (var i = 0; i < floors; i++)
{
for ( i = 0; i < floors; i++ ) {
this.box(blocks.iron,20,1,20)
.up()
.box0(blocks.glass_pane,20,3,20)

View file

@ -730,7 +730,7 @@ loop. The following `while` loop counts to 100...
```javascript
var i = 1;
while (i <= 100){
while ( i <= 100 ) {
console.log( i );
i = i + 1;
}
@ -857,12 +857,12 @@ type the following...
```javascript
var myskyscraper = function(floors) {
if (typeof floors == 'undefined'){
var i ;
if ( typeof floors == 'undefined' ) {
floors = 10;
}
this.chkpt('myskyscraper'); // saves the drone position so it can return there later
for (var i = 0; i < floors; i++)
{
for ( i = 0; i < floors; i++ ) {
this.box(blocks.iron,20,1,20)
.up()
.box0(blocks.glass_pane,20,3,20)

View file

@ -46,29 +46,36 @@ function each time the event is fired.
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){
evt.player.sendMessage( evt.player.name + ' broke a block!');
});
```javascript
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
evt.player.sendMessage( evt.player.name + ' broke a block!');
} );
```
To handle an event only once and unregister from further events...
events.on('block.BlockBreakEvent', function(listener, evt){
evt.player.sendMessage( evt.player.name + ' broke a block!');
evt.handlers.unregister(listener);
});
```javascript
events.on( 'block.BlockBreakEvent', function( listener, evt ) {
evt.player.sendMessage( 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);
```javascript
var myBlockBreakListener = events.on( 'block.BlockBreakEvent', function( l, e ) { ... } );
...
var handlers = org.bukkit.event.block.BlockBreakEvent.getHandlerList();
handlers.unregister(myBlockBreakListener);
```
To listen for events using a full class name as the `eventName` parameter...
events.on(org.bukkit.event.block.BlockBreakEvent, function(listener, evt){
evt.player.sendMessage( evt.player.name + ' broke a block!');
});
```javascript
events.on( org.bukkit.event.block.BlockBreakEvent, function( listener, evt ) {
evt.player.sendMessage( evt.player.name + ' broke a block!');
} );
```
[buk2]: http://wiki.bukkit.org/Event_API_Reference
[buk]: http://jd.bukkit.org/dev/apidocs/index.html?org/bukkit/event/Event.html

View file

@ -37,30 +37,31 @@ an interactive sign.
#### Example: Create a sign which changes the time of day.
##### plugins/signs/time-of-day.js
var utils = require('utils'),
signs = require('signs');
```javascript
var utils = require('utils'),
signs = require('signs');
var onTimeChoice = function(event){
var selectedIndex = event.number;
// convert to Minecraft time 0 = Dawn, 6000 = midday, 12000 = dusk, 18000 = midnight
var time = selectedIndex * 6000;
event.player.location.world.setTime(time);
};
var onTimeChoice = function(event){
var selectedIndex = event.number;
// convert to Minecraft time 0 = Dawn, 6000 = midday, 12000 = dusk, 18000 = midnight
var time = selectedIndex * 6000;
event.player.location.world.setTime(time);
};
// signs.menu returns a function which can be called for one or more signs in the game.
var convertToTimeMenu = signs.menu('Time of Day',
['Dawn', 'Midday', 'Dusk', 'Midnight'],
onTimeChoice);
// signs.menu returns a function which can be called for one or more signs in the game.
var convertToTimeMenu = signs.menu('Time of Day',
['Dawn', 'Midday', 'Dusk', 'Midnight'],
onTimeChoice);
exports.time_sign = function( player ){
var sign = signs.getTargetedBy(player);
if (!sign){
throw new Error('You must look at a sign');
}
convertToTimeMenu(sign);
};
exports.time_sign = function( player ){
var sign = signs.getTargetedBy(player);
if ( !sign ) {
throw new Error('You must look at a sign');
}
convertToTimeMenu(sign);
};
```
To use the above function at the in-game prompt, look at an existing
sign and type...
@ -78,13 +79,15 @@ the entity has targeted. It is a utility function for use by plugin authors.
#### Example
var signs = require('signs'),
utils = require('utils');
var player = utils.player('tom1234');
var sign = signs.getTargetedBy( player );
if (!sign){
player.sendMessage('Not looking at a sign');
}
```javascript
var signs = require('signs'),
utils = require('utils');
var player = utils.player('tom1234');
var sign = signs.getTargetedBy( player );
if ( !sign ) {
player.sendMessage('Not looking at a sign');
}
```
[buksign]: http://jd.bukkit.org/dev/apidocs/org/bukkit/block/Sign.html