better tab completion on /jsp issue #35
This commit is contained in:
parent
446ba9ad7b
commit
1732bf15dd
2 changed files with 101 additions and 75 deletions
|
@ -54,6 +54,8 @@ command("alias",function(params){
|
||||||
self.sendMessage(alias.list(self));
|
self.sendMessage(alias.list(self));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (params.length == 0)
|
||||||
|
return self.sendMessage(alias.help());
|
||||||
|
|
||||||
var playerHasAliases = alias.store.players[self.name];
|
var playerHasAliases = alias.store.players[self.name];
|
||||||
if (!playerHasAliases)
|
if (!playerHasAliases)
|
||||||
|
@ -65,7 +67,7 @@ command("alias",function(params){
|
||||||
for (var i = 0;i < commands.length; i++){
|
for (var i = 0;i < commands.length; i++){
|
||||||
// fill in template
|
// fill in template
|
||||||
var cmd = commands[i];
|
var cmd = commands[i];
|
||||||
cmd = cmd.replace(/{([0-9]*)}/g,function(dummy,index){ return params[index];})
|
cmd = cmd.replace(/{([0-9]*)}/g,function(dummy,index){ return params[index] || "";})
|
||||||
self.performCommand(cmd);
|
self.performCommand(cmd);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
var global = this;
|
var global = this;
|
||||||
var verbose = verbose || false;
|
var verbose = verbose || false;
|
||||||
/*
|
/*
|
||||||
wph 20130124 - make self, plugin and bukkit public - these are far more useful now that tab-complete works.
|
wph 20130124 - make self, plugin and server public - these are far more useful now that tab-complete works.
|
||||||
*/
|
*/
|
||||||
var server = org.bukkit.Bukkit.server;
|
var server = org.bukkit.Bukkit.server;
|
||||||
//
|
//
|
||||||
|
@ -128,7 +128,6 @@ var server = org.bukkit.Bukkit.server;
|
||||||
Save a javascript object to a file (saves using JSON notation)
|
Save a javascript object to a file (saves using JSON notation)
|
||||||
*/
|
*/
|
||||||
var _save = function(object, filename){
|
var _save = function(object, filename){
|
||||||
print(filename);
|
|
||||||
var objectToStr = null;
|
var objectToStr = null;
|
||||||
try{
|
try{
|
||||||
objectToStr = JSON.stringify(object);
|
objectToStr = JSON.stringify(object);
|
||||||
|
@ -175,7 +174,8 @@ var server = org.bukkit.Bukkit.server;
|
||||||
command management - allow for non-ops to execute approved javascript code.
|
command management - allow for non-ops to execute approved javascript code.
|
||||||
*/
|
*/
|
||||||
var _commands = {};
|
var _commands = {};
|
||||||
var _command = function(name,func,options,intercepts){
|
var _command = function(name,func,options,intercepts)
|
||||||
|
{
|
||||||
if (typeof name == "undefined"){
|
if (typeof name == "undefined"){
|
||||||
// it's an invocation from the Java Plugin!
|
// it's an invocation from the Java Plugin!
|
||||||
if (__cmdArgs.length === 0)
|
if (__cmdArgs.length === 0)
|
||||||
|
@ -266,13 +266,37 @@ var server = org.bukkit.Bukkit.server;
|
||||||
var __onTabCompleteJSP = function() {
|
var __onTabCompleteJSP = function() {
|
||||||
var result = global.__onTC_result;
|
var result = global.__onTC_result;
|
||||||
var args = global.__onTC_args;
|
var args = global.__onTC_args;
|
||||||
var cmd = _commands[args[0]];
|
var cmdInput = args[0];
|
||||||
if (cmd)
|
var cmd = _commands[cmdInput];
|
||||||
for (var i = 0;i < cmd.options.length; i++)
|
if (cmd){
|
||||||
result.add(cmd.options[i]);
|
var opts = cmd.options;
|
||||||
else
|
var len = opts.length;
|
||||||
|
if (args.length == 1){
|
||||||
|
for (var i = 0;i < len; i++)
|
||||||
|
result.add(opts[i]);
|
||||||
|
}else{
|
||||||
|
// partial e.g. /jsp chat_color dar
|
||||||
|
for (var i = 0;i < len; i++){
|
||||||
|
if (opts[i].indexOf(args[1]) == 0){
|
||||||
|
result.add(opts[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if (args.length == 0){
|
||||||
for (var i in _commands)
|
for (var i in _commands)
|
||||||
result.add(i);
|
result.add(i);
|
||||||
|
}else{
|
||||||
|
// partial e.g. /jsp al
|
||||||
|
// should tabcomplete to alias
|
||||||
|
//
|
||||||
|
for (var c in _commands){
|
||||||
|
if (c.indexOf(cmdInput) == 0){
|
||||||
|
result.add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
|
|
Reference in a new issue