Omit abstract event classes from events-helper.

Improved tab completion for jre8
This commit is contained in:
walterhiggins 2014-04-26 20:20:10 +01:00
parent d8cfcb4572
commit 2ba3335a16
17 changed files with 55 additions and 159 deletions

View file

@ -1,2 +1,2 @@
bukkit-version=1.7.2 bukkit-version=1.7.9
scriptcraft-version=2.0.6 scriptcraft-version=2.0.8

View file

@ -89,6 +89,7 @@
<java classname="jscript" failonerror="true" fork="true" output="${dist}/js/lib/events-helper.js"> <java classname="jscript" failonerror="true" fork="true" output="${dist}/js/lib/events-helper.js">
<classpath> <classpath>
<pathelement path="src/docs/java"/> <pathelement path="src/docs/java"/>
<pathelement path="${minecraft.dir}/craftbukkit.jar"/>
</classpath> </classpath>
<arg value="src/generateEventsHelper.js"/> <arg value="src/generateEventsHelper.js"/>
</java> </java>

View file

@ -48,9 +48,6 @@ Walter Higgins
* [Using string substitutions](#using-string-substitutions) * [Using string substitutions](#using-string-substitutions)
* [Events Helper Module](#events-helper-module) * [Events Helper Module](#events-helper-module)
* [Usage](#usage) * [Usage](#usage)
* [events.hanging()](#eventshanging)
* [events.world()](#eventsworld)
* [events.chunk()](#eventschunk)
* [events.worldUnload()](#eventsworldunload) * [events.worldUnload()](#eventsworldunload)
* [events.worldLoad()](#eventsworldload) * [events.worldLoad()](#eventsworldload)
* [events.chunkLoad()](#eventschunkload) * [events.chunkLoad()](#eventschunkload)
@ -59,7 +56,6 @@ Walter Higgins
* [events.spawnChange()](#eventsspawnchange) * [events.spawnChange()](#eventsspawnchange)
* [events.chunkUnload()](#eventschunkunload) * [events.chunkUnload()](#eventschunkunload)
* [events.worldInit()](#eventsworldinit) * [events.worldInit()](#eventsworldinit)
* [events.entity()](#eventsentity)
* [events.horseJump()](#eventshorsejump) * [events.horseJump()](#eventshorsejump)
* [events.entityCombust()](#eventsentitycombust) * [events.entityCombust()](#eventsentitycombust)
* [events.entityRegainHealth()](#eventsentityregainhealth) * [events.entityRegainHealth()](#eventsentityregainhealth)
@ -92,30 +88,22 @@ Walter Higgins
* [events.itemSpawn()](#eventsitemspawn) * [events.itemSpawn()](#eventsitemspawn)
* [events.sheepDyeWool()](#eventssheepdyewool) * [events.sheepDyeWool()](#eventssheepdyewool)
* [events.entityTeleport()](#eventsentityteleport) * [events.entityTeleport()](#eventsentityteleport)
* [events.block()](#eventsblock)
* [events.blockFade()](#eventsblockfade) * [events.blockFade()](#eventsblockfade)
* [events.blockDamage()](#eventsblockdamage) * [events.blockDamage()](#eventsblockdamage)
* [events.blockPiston()](#eventsblockpiston)
* [events.blockPistonExtend()](#eventsblockpistonextend) * [events.blockPistonExtend()](#eventsblockpistonextend)
* [events.blockExp()](#eventsblockexp) * [events.blockExp()](#eventsblockexp)
* [events.blockGrow()](#eventsblockgrow) * [events.blockGrow()](#eventsblockgrow)
* [events.blockPistonRetract()](#eventsblockpistonretract) * [events.blockPistonRetract()](#eventsblockpistonretract)
* [events.blockDispense()](#eventsblockdispense) * [events.blockDispense()](#eventsblockdispense)
* [events.blockBreak()](#eventsblockbreak) * [events.blockBreak()](#eventsblockbreak)
* [events.painting()](#eventspainting)
* [events.paintingPlace()](#eventspaintingplace) * [events.paintingPlace()](#eventspaintingplace)
* [events.weather()](#eventsweather)
* [events.lightningStrike()](#eventslightningstrike) * [events.lightningStrike()](#eventslightningstrike)
* [events.vehicle()](#eventsvehicle)
* [events.vehicleEnter()](#eventsvehicleenter) * [events.vehicleEnter()](#eventsvehicleenter)
* [events.vehicleMove()](#eventsvehiclemove) * [events.vehicleMove()](#eventsvehiclemove)
* [events.vehicleCollision()](#eventsvehiclecollision)
* [events.vehicleCreate()](#eventsvehiclecreate) * [events.vehicleCreate()](#eventsvehiclecreate)
* [events.asyncPlayerPreLogin()](#eventsasyncplayerprelogin) * [events.asyncPlayerPreLogin()](#eventsasyncplayerprelogin)
* [events.playerUnleashEntity()](#eventsplayerunleashentity) * [events.playerUnleashEntity()](#eventsplayerunleashentity)
* [events.playerPreLogin()](#eventsplayerprelogin) * [events.playerPreLogin()](#eventsplayerprelogin)
* [events.player()](#eventsplayer)
* [events.server()](#eventsserver)
* [events.inventoryPickupItem()](#eventsinventorypickupitem) * [events.inventoryPickupItem()](#eventsinventorypickupitem)
* [events.inventoryMoveItem()](#eventsinventorymoveitem) * [events.inventoryMoveItem()](#eventsinventorymoveitem)
* [events.furnaceBurn()](#eventsfurnaceburn) * [events.furnaceBurn()](#eventsfurnaceburn)
@ -194,7 +182,6 @@ Walter Higgins
* [events.playerToggleFlight()](#eventsplayertoggleflight) * [events.playerToggleFlight()](#eventsplayertoggleflight)
* [events.playerAnimation()](#eventsplayeranimation) * [events.playerAnimation()](#eventsplayeranimation)
* [events.asyncPlayerChat()](#eventsasyncplayerchat) * [events.asyncPlayerChat()](#eventsasyncplayerchat)
* [events.playerBucket()](#eventsplayerbucket)
* [events.playerRegisterChannel()](#eventsplayerregisterchannel) * [events.playerRegisterChannel()](#eventsplayerregisterchannel)
* [events.playerMove()](#eventsplayermove) * [events.playerMove()](#eventsplayermove)
* [events.playerTeleport()](#eventsplayerteleport) * [events.playerTeleport()](#eventsplayerteleport)
@ -206,8 +193,6 @@ Walter Higgins
* [events.serverCommand()](#eventsservercommand) * [events.serverCommand()](#eventsservercommand)
* [events.remoteServerCommand()](#eventsremoteservercommand) * [events.remoteServerCommand()](#eventsremoteservercommand)
* [events.mapInitialize()](#eventsmapinitialize) * [events.mapInitialize()](#eventsmapinitialize)
* [events.service()](#eventsservice)
* [events.plugin()](#eventsplugin)
* [events.serviceRegister()](#eventsserviceregister) * [events.serviceRegister()](#eventsserviceregister)
* [events.serverListPing()](#eventsserverlistping) * [events.serverListPing()](#eventsserverlistping)
* [events.serviceUnregister()](#eventsserviceunregister) * [events.serviceUnregister()](#eventsserviceunregister)
@ -963,30 +948,6 @@ The crucial difference is that the events module will have functions for each
of the built-in events so tab-completion will help of the built-in events so tab-completion will help
beginning programmers to explore the events at the server console window. beginning programmers to explore the events at the server console window.
### events.hanging()
#### Parameters
* callback - A function which is called whenever the hanging.HangingEvent event is fired
see events.on() for more information.
### events.world()
#### Parameters
* callback - A function which is called whenever the world.WorldEvent event is fired
see events.on() for more information.
### events.chunk()
#### Parameters
* callback - A function which is called whenever the world.ChunkEvent event is fired
see events.on() for more information.
### events.worldUnload() ### events.worldUnload()
#### Parameters #### Parameters
@ -1051,14 +1012,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.entity()
#### Parameters
* callback - A function which is called whenever the entity.EntityEvent event is fired
see events.on() for more information.
### events.horseJump() ### events.horseJump()
#### Parameters #### Parameters
@ -1315,14 +1268,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.block()
#### Parameters
* callback - A function which is called whenever the block.BlockEvent event is fired
see events.on() for more information.
### events.blockFade() ### events.blockFade()
#### Parameters #### Parameters
@ -1339,14 +1284,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.blockPiston()
#### Parameters
* callback - A function which is called whenever the block.BlockPistonEvent event is fired
see events.on() for more information.
### events.blockPistonExtend() ### events.blockPistonExtend()
#### Parameters #### Parameters
@ -1395,14 +1332,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.painting()
#### Parameters
* callback - A function which is called whenever the painting.PaintingEvent event is fired
see events.on() for more information.
### events.paintingPlace() ### events.paintingPlace()
#### Parameters #### Parameters
@ -1411,14 +1340,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.weather()
#### Parameters
* callback - A function which is called whenever the weather.WeatherEvent event is fired
see events.on() for more information.
### events.lightningStrike() ### events.lightningStrike()
#### Parameters #### Parameters
@ -1427,14 +1348,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.vehicle()
#### Parameters
* callback - A function which is called whenever the vehicle.VehicleEvent event is fired
see events.on() for more information.
### events.vehicleEnter() ### events.vehicleEnter()
#### Parameters #### Parameters
@ -1451,14 +1364,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.vehicleCollision()
#### Parameters
* callback - A function which is called whenever the vehicle.VehicleCollisionEvent event is fired
see events.on() for more information.
### events.vehicleCreate() ### events.vehicleCreate()
#### Parameters #### Parameters
@ -1491,22 +1396,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.player()
#### Parameters
* callback - A function which is called whenever the player.PlayerEvent event is fired
see events.on() for more information.
### events.server()
#### Parameters
* callback - A function which is called whenever the server.ServerEvent event is fired
see events.on() for more information.
### events.inventoryPickupItem() ### events.inventoryPickupItem()
#### Parameters #### Parameters
@ -2131,14 +2020,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.playerBucket()
#### Parameters
* callback - A function which is called whenever the player.PlayerBucketEvent event is fired
see events.on() for more information.
### events.playerRegisterChannel() ### events.playerRegisterChannel()
#### Parameters #### Parameters
@ -2227,22 +2108,6 @@ see events.on() for more information.
see events.on() for more information. see events.on() for more information.
### events.service()
#### Parameters
* callback - A function which is called whenever the server.ServiceEvent event is fired
see events.on() for more information.
### events.plugin()
#### Parameters
* callback - A function which is called whenever the server.PluginEvent event is fired
see events.on() for more information.
### events.serviceRegister() ### events.serviceRegister()
#### Parameters #### Parameters
@ -3138,7 +3003,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( event) { events.blockBreak( 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...
@ -4046,7 +3911,6 @@ Source Code ...
A simple event-driven minecraft plugin. How to handle Events. A simple event-driven minecraft plugin. How to handle Events.
This example demonstrates event-driven programming. The code below This example demonstrates event-driven programming. The code below
will display the version of ScriptCraft every time an operator joins will display the version of ScriptCraft every time an operator joins
the game. This module is notable from previous modules for the the game. This module is notable from previous modules for the
@ -4128,6 +3992,14 @@ cleaner and more readable. Similarly where you see a method like
} }
}); });
Update: Since version 2.0.8 the above code can be replaced by the more succinct:
events.playerJoin( function( event ) {
if ( event.player.op ) {
event.player.sendMessage('Welcome to ' + __plugin);
}
});
## Arrows Plugin ## Arrows Plugin
The arrows mod adds fancy arrows to the game. Arrows which... The arrows mod adds fancy arrows to the game. Arrows which...

View file

@ -36,6 +36,13 @@ while ( ( entry = zis.nextEntry) != null) {
var name = '' + entry.name; var name = '' + entry.name;
if (name.match(/org\/bukkit\/event\/.+Event\.class$/)){ if (name.match(/org\/bukkit\/event\/.+Event\.class$/)){
name = name.replace(/\//g,'.').replace('.class',''); name = name.replace(/\//g,'.').replace('.class','');
// abstract events don't have a static getHandlerList method so
// shouldn't be added to this module
var hasHandlerList = eval(name + '.getHandlerList');
if ( !hasHandlerList ) {
continue;
}
var parts = name.split('.'); var parts = name.split('.');
var shortName = name.replace('org.bukkit.event.',''); var shortName = name.replace('org.bukkit.event.','');
var fname = parts.reverse().shift().replace(/^(.)/,function(a){ return a.toLowerCase()}).replace(/Event$/,''); var fname = parts.reverse().shift().replace(/^(.)/,function(a){ return a.toLowerCase()}).replace(/Event$/,'');

View file

@ -1,3 +1,6 @@
exports.isJavaObject = function( o ) { exports.isJavaObject = function( o ) {
if (o === global){
return false;
}
return o instanceof java.lang.Object; return o instanceof java.lang.Object;
}; };

View file

@ -619,15 +619,16 @@ 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( evt ) { // wph 20131226 - make events global as it is used by many plugins/modules
global.events = events;
events.pluginDisable(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' ) );
_runUnloadHandlers(); _runUnloadHandlers();
org.bukkit.event.HandlerList['unregisterAll(org.bukkit.plugin.Plugin)'](__plugin); org.bukkit.event.HandlerList['unregisterAll(org.bukkit.plugin.Plugin)'](__plugin);
}); });
// wph 20131226 - make events global as it is used by many plugins/modules
global.events = events;
global.__onCommand = function( sender, cmd, label, args) { global.__onCommand = function( sender, cmd, label, args) {

View file

@ -24,6 +24,7 @@ var _getProperties = function( o ) {
i, i,
j, j,
isObjectMethod, isObjectMethod,
propValue,
typeofProperty; typeofProperty;
if ( isJavaObject( o ) ) { if ( isJavaObject( o ) ) {
@ -49,12 +50,14 @@ var _getProperties = function( o ) {
} }
typeofProperty = null; typeofProperty = null;
try { try {
typeofProperty = typeof o[i]; propValue = o[i];
typeofProperty = typeof propValue;
} catch( e ) { } catch( e ) {
if ( e.message == 'java.lang.IllegalStateException: Entity not leashed' ) { if ( e.message == 'java.lang.IllegalStateException: Entity not leashed' ) {
// wph 20131020 fail silently for Entity leashing in craftbukkit // wph 20131020 fail silently for Entity leashing in craftbukkit
} else { } else {
throw e; // don't throw an error during tab completion just make a best effort to
// do the job.
} }
} }
if ( typeofProperty == 'function' ) { if ( typeofProperty == 'function' ) {
@ -119,6 +122,9 @@ var onTabCompleteJS = function( result, cmdSender, pluginCmd, cmdAlias, cmdArgs
if ( statement.length == 0 ) { if ( statement.length == 0 ) {
propsOfLastArg = _globalSymbols; propsOfLastArg = _globalSymbols;
} else { } else {
if (statement.match(/\)$/)){
return;
}
statementSyms = statement.split(/[^\$a-zA-Z0-9_\.]/); statementSyms = statement.split(/[^\$a-zA-Z0-9_\.]/);
lastSymbol = statementSyms[statementSyms.length-1]; lastSymbol = statementSyms[statementSyms.length-1];

View file

@ -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( event ) { events.playerInteract( 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.

View file

@ -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( evt ) { events.playerCommandPreprocess( 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( evt ) {
command('void',function( ) { command('void',function( ) {
} ); } );
events.on( 'server.ServerCommandEvent', function( evt ) { events.serverCommand( 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);

View file

@ -121,5 +121,5 @@ var _onArrowHit = function( event ) {
} }
} }
}; };
events.on( 'entity.ProjectileHitEvent', _onArrowHit ); events.projectileHit( _onArrowHit );

View file

@ -73,7 +73,7 @@ foreach( colors, function ( color, i ) {
colorCodes[color] = i.toString( 16 ); colorCodes[color] = i.toString( 16 );
} ); } );
events.on( 'player.AsyncPlayerChatEvent', function( event ) { events.asyncPlayerChat( function( event ) {
var player = event.player; var player = event.player;
var playerChatColor = _store.players[ player.name ]; var playerChatColor = _store.players[ player.name ];
if ( playerChatColor ) { if ( playerChatColor ) {

View file

@ -158,7 +158,7 @@ var classroom = plugin('classroom', {
exports.classroom = classroom; exports.classroom = classroom;
events.on( 'player.PlayerJoinEvent', function( event ) { events.playerJoin( function( event ) {
if ( _store.enableScripting ) { if ( _store.enableScripting ) {
grantScripting(event.player); grantScripting(event.player);
} }

View file

@ -84,7 +84,7 @@ exports.commando = function( name, func, options, intercepts ) {
return result; return result;
}; };
events.on( 'player.PlayerCommandPreprocessEvent', function( evt ) { events.playerCommandPreprocess( function( evt ) {
var msg = '' + evt.message; var msg = '' + evt.message;
var parts = msg.match( /^\/([^\s]+)/ ); var parts = msg.match( /^\/([^\s]+)/ );
if ( !parts ) { if ( !parts ) {
@ -98,7 +98,7 @@ events.on( 'player.PlayerCommandPreprocessEvent', function( evt ) {
evt.message = '/jsp ' + msg.replace( /^\//, '' ); evt.message = '/jsp ' + msg.replace( /^\//, '' );
} }
} ); } );
events.on( 'server.ServerCommandEvent', function( evt ) { events.serverCommand( function( evt ) {
var msg = '' + evt.command; var msg = '' + evt.command;
var parts = msg.match( /^\/*([^\s]+)/ ); var parts = msg.match( /^\/*([^\s]+)/ );
if ( !parts ) { if ( !parts ) {

View file

@ -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( event) { events.blockBreak( 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...

View file

@ -3,7 +3,6 @@
A simple event-driven minecraft plugin. How to handle Events. A simple event-driven minecraft plugin. How to handle Events.
This example demonstrates event-driven programming. The code below This example demonstrates event-driven programming. The code below
will display the version of ScriptCraft every time an operator joins will display the version of ScriptCraft every time an operator joins
the game. This module is notable from previous modules for the the game. This module is notable from previous modules for the
@ -85,6 +84,14 @@ cleaner and more readable. Similarly where you see a method like
} }
}); });
Update: Since version 2.0.8 the above code can be replaced by the more succinct:
events.playerJoin( function( event ) {
if ( event.player.op ) {
event.player.sendMessage('Welcome to ' + __plugin);
}
});
***/ ***/
events.on( 'player.PlayerJoinEvent', function( event ) { events.on( 'player.PlayerJoinEvent', function( event ) {
if ( event.player.op ) { if ( event.player.op ) {

View file

@ -43,7 +43,6 @@ cover to make the game more fun.
***/ ***/
var bkGameMode = org.bukkit.GameMode, var bkGameMode = org.bukkit.GameMode,
bkEntityDamageByEntityEvent = org.bukkit.event.entity.EntityDamageByEntityEvent,
bkItemStack = org.bukkit.inventory.ItemStack, bkItemStack = org.bukkit.inventory.ItemStack,
bkMaterial = org.bukkit.Material, bkMaterial = org.bukkit.Material,
bkSnowball = org.bukkit.entity.Snowball; bkSnowball = org.bukkit.entity.Snowball;
@ -196,7 +195,7 @@ var createGame = function( duration, teams ) {
return { return {
start: function( ) { start: function( ) {
_startGame( _gameState ); _startGame( _gameState );
_gameState.listener = events.on(bkEntityDamageByEntityEvent,_onSnowballHit); _gameState.listener = events.entityDamageByEntity( _onSnowballHit );
new java.lang.Thread( function( ) { new java.lang.Thread( function( ) {
while ( _gameState.duration-- ) { while ( _gameState.duration-- ) {
java.lang.Thread.sleep( 1000 ); // sleep 1,000 millisecs (1 second) java.lang.Thread.sleep( 1000 ); // sleep 1,000 millisecs (1 second)

View file

@ -94,9 +94,9 @@ var _startGame = function( ) {
console.log('Staring game: Cow Clicker'); console.log('Staring game: Cow Clicker');
} }
events.on( 'player.PlayerQuitEvent', _onPlayerQuit ); events.playerQuit( _onPlayerQuit );
events.on( 'player.PlayerJoinEvent', _onPlayerJoin ); events.playerJoin( _onPlayerJoin );
events.on( 'player.PlayerInteractEntityEvent', _onPlayerInteract ); events.playerInteractEntity( _onPlayerInteract );
scoreboard.start(); scoreboard.start();