This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/js/lib/tabcomplete-jsp.js
walterhiggins 19162c3688 First phase of transition from Bukkit to Canary.
Some of the plugins are not yet supported.
If you're feeling brave you can build from source using ant.
2014-09-29 23:42:41 +01:00

49 lines
1,012 B
JavaScript

'use strict';
var _commands = require('command').commands;
/*
Tab completion for the /jsp commmand
*/
var __onTabCompleteJSP = function( result, cmdArgs ) {
var cmdInput = cmdArgs[0],
opts,
cmd,
len,
i;
cmd = _commands[cmdInput];
if ( cmd ) {
if (typeof cmd.options === 'function'){
opts = cmd.options();
} else {
opts = cmd.options;
}
len = opts.length;
if ( cmdArgs.length > 1 ) {
// partial e.g. /jsp chat_color dar
for ( i = 0; i < len; i++ ) {
if ( opts[i].indexOf( cmdArgs[1] ) == 0 ) {
result.add( opts[i] );
}
}
}
} else {
if ( cmdArgs.length == 0 ) {
for ( i in _commands ) {
result.add( i );
}
} else {
// partial e.g. /jsp ho
// should tabcomplete to home
//
for ( i in _commands ) {
if ( i.indexOf( cmdInput ) == 0 ) {
result.add( i );
}
}
}
}
return result;
};
module.exports = __onTabCompleteJSP;