2014-04-26 17:56:57 +02:00
|
|
|
var File = java.io.File,
|
|
|
|
FileReader = java.io.FileReader,
|
|
|
|
FileInputStream = java.io.FileInputStream,
|
|
|
|
out = java.lang.System.out,
|
|
|
|
ZipInputStream = java.util.zip.ZipInputStream,
|
|
|
|
zis = new ZipInputStream(new FileInputStream('./target/minecraft/craftbukkit.jar')),
|
|
|
|
entry = null;
|
|
|
|
var content = [
|
|
|
|
'/*********************',
|
|
|
|
'## Events Helper Module',
|
|
|
|
'The Events helper module provides a suite of functions one for each possible event.',
|
|
|
|
'For example, the blockBreak function in turn calls events.on(org.bukkit.event.block.BlockBreakEvent, callback, priority)',
|
|
|
|
'This module is a convenience wrapper for easily add new event handlers.',
|
|
|
|
'### Usage',
|
|
|
|
'',
|
|
|
|
' events.blockBreak(function(evt){ ',
|
|
|
|
' evt.player.sendMessage("You broke a block!"); ',
|
|
|
|
' });',
|
|
|
|
'',
|
|
|
|
'... which is just a shorter way of writing ...',
|
|
|
|
'',
|
|
|
|
' events.on("block.BlockBreakEvent",function(evt){ ',
|
|
|
|
' evt.player.sendMessage("You broke a block!");',
|
|
|
|
' });',
|
|
|
|
'',
|
|
|
|
'The crucial difference is that the events module will have functions for each ',
|
|
|
|
'of the built-in events so tab-completion will help ',
|
|
|
|
'beginning programmers to explore the events at the server console window.',
|
2014-04-26 18:14:32 +02:00
|
|
|
'',
|
|
|
|
'***/'
|
2014-04-26 17:56:57 +02:00
|
|
|
];
|
|
|
|
for (var i = 0; i< content.length; i++){
|
|
|
|
out.println(content[i]);
|
|
|
|
}
|
|
|
|
while ( ( entry = zis.nextEntry) != null) {
|
|
|
|
var name = '' + entry.name;
|
|
|
|
if (name.match(/org\/bukkit\/event\/.+Event\.class$/)){
|
|
|
|
name = name.replace(/\//g,'.').replace('.class','');
|
2014-04-26 21:20:10 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2014-04-26 17:56:57 +02:00
|
|
|
var parts = name.split('.');
|
|
|
|
var shortName = name.replace('org.bukkit.event.','');
|
|
|
|
var fname = parts.reverse().shift().replace(/^(.)/,function(a){ return a.toLowerCase()}).replace(/Event$/,'');
|
|
|
|
|
|
|
|
var comment = [
|
|
|
|
'/*********************',
|
2014-04-26 18:03:08 +02:00
|
|
|
'### events.' + fname + '()',
|
2014-04-26 18:14:32 +02:00
|
|
|
'',
|
2014-04-26 17:56:57 +02:00
|
|
|
'#### Parameters ',
|
2014-04-26 18:14:32 +02:00
|
|
|
'',
|
2014-04-26 17:56:57 +02:00
|
|
|
' * callback - A function which is called whenever the ' + shortName + ' event is fired',
|
2014-04-26 18:14:32 +02:00
|
|
|
'',
|
2014-04-26 21:24:45 +02:00
|
|
|
' * priority - optional - see events.on() for more information.',
|
2014-04-26 18:14:32 +02:00
|
|
|
'',
|
2014-04-26 17:56:57 +02:00
|
|
|
'***/'
|
|
|
|
];
|
|
|
|
for (var i = 0; i < comment.length; i++){
|
|
|
|
out.println(comment[i]);
|
|
|
|
}
|
|
|
|
out.println('exports.' + fname + ' = function(callback,priority){ ');
|
|
|
|
out.println(' return events.on(' + name + ',callback,priority);');
|
|
|
|
out.println('};');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|