Workaround for stupid array index notation access bug in Nashorn.
This commit is contained in:
parent
9a2b39b108
commit
a098963f90
4 changed files with 57 additions and 41 deletions
|
@ -2457,11 +2457,11 @@ such an alias)...
|
|||
|
||||
/jsp alias global stormy = time 18000; weather storm
|
||||
|
||||
To delete an alias ...
|
||||
To remove an alias ...
|
||||
|
||||
/jsp alias delete cw
|
||||
/jsp alias remove cw
|
||||
|
||||
... deletes the 'cw' alias from the appropriate alias map.
|
||||
... removes the 'cw' alias from the appropriate alias map.
|
||||
|
||||
To get a list of aliases currently defined...
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@ var _cmdInterceptors = [];
|
|||
*/
|
||||
var executeCmd = function(args, player){
|
||||
if (args.length === 0)
|
||||
throw new Error("Usage: jsp command-name command-parameters");
|
||||
throw new Error('Usage: jsp command-name command-parameters');
|
||||
var name = args[0];
|
||||
var cmd = _commands[name];
|
||||
if (typeof cmd === "undefined"){
|
||||
if (typeof cmd === 'undefined'){
|
||||
// it's not a global command - pass it on to interceptors
|
||||
var intercepted = false;
|
||||
for (var i = 0;i < _cmdInterceptors.length;i++){
|
||||
|
@ -26,7 +26,7 @@ var executeCmd = function(args, player){
|
|||
try {
|
||||
result = cmd.callback(args.slice(1),player);
|
||||
}catch (e){
|
||||
console.error("Error while trying to execute command: " + JSON.stringify(args));
|
||||
console.error('Error while trying to execute command: ' + JSON.stringify(args));
|
||||
throw e;
|
||||
}
|
||||
return result;
|
||||
|
@ -36,16 +36,13 @@ var executeCmd = function(args, player){
|
|||
define a new JSP command.
|
||||
*/
|
||||
var defineCmd = function(name, func, options, intercepts) {
|
||||
if (typeof options == "undefined")
|
||||
if (typeof options == 'undefined')
|
||||
options = [];
|
||||
_commands[name] = {callback: func, options: options};
|
||||
if (intercepts)
|
||||
_cmdInterceptors.push(func);
|
||||
return func;
|
||||
};
|
||||
var _command = function(name, func, options, intercepts) {
|
||||
return defineCmd(name, func, options, intercepts);
|
||||
};
|
||||
_command.exec = executeCmd;
|
||||
exports.command = _command;
|
||||
exports.command = defineCmd;
|
||||
exports.commands = _commands;
|
||||
exports.exec = executeCmd;
|
||||
|
|
|
@ -573,7 +573,8 @@ function __onEnable (__engine, __plugin, __script)
|
|||
*/
|
||||
require('persistence')(jsPluginsRootDir,global);
|
||||
|
||||
global.command = require('command').command;
|
||||
var cmdModule = require('command');
|
||||
global.command = cmdModule.command;
|
||||
var plugins = require('plugin');
|
||||
global.__onTabComplete = require('tabcomplete');
|
||||
global.plugin = plugins.plugin;
|
||||
|
@ -593,7 +594,9 @@ function __onEnable (__engine, __plugin, __script)
|
|||
global.__onCommand = function( sender, cmd, label, args) {
|
||||
var jsArgs = [];
|
||||
var i = 0;
|
||||
for (;i < args.length; i++) jsArgs.push('' + args[i]);
|
||||
for (;i < args.length; i++) {
|
||||
jsArgs.push('' + args[i]);
|
||||
}
|
||||
|
||||
var result = false;
|
||||
var cmdName = ('' + cmd.name).toLowerCase();
|
||||
|
@ -616,7 +619,7 @@ function __onEnable (__engine, __plugin, __script)
|
|||
}
|
||||
}
|
||||
if (cmdName == 'jsp'){
|
||||
command.exec(jsArgs, sender);
|
||||
cmdModule.exec(jsArgs, sender);
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -31,11 +31,11 @@ such an alias)...
|
|||
|
||||
/jsp alias global stormy = time 18000; weather storm
|
||||
|
||||
To delete an alias ...
|
||||
To remove an alias ...
|
||||
|
||||
/jsp alias delete cw
|
||||
/jsp alias remove cw
|
||||
|
||||
... deletes the 'cw' alias from the appropriate alias map.
|
||||
... removes the 'cw' alias from the appropriate alias map.
|
||||
|
||||
To get a list of aliases currently defined...
|
||||
|
||||
|
@ -55,7 +55,7 @@ var _usage = "\
|
|||
/jsp alias set {alias} = {comand-1} ;{command-2}\n \
|
||||
/jsp alias global {alias} = {command-1} ; {command-2}\n \
|
||||
/jsp alias list\n \
|
||||
/jsp alias delete {alias}\n \
|
||||
/jsp alias remove {alias}\n \
|
||||
Create a new alias : \n \
|
||||
/jsp alias set cw = time set {1} ; weather {2}\n \
|
||||
Execute the alias : \n \
|
||||
|
@ -81,7 +81,7 @@ var _processParams = function(params){
|
|||
return { cmd: aliasCmd, aliases: aliasValue.split(/\s*;\s*/) };
|
||||
};
|
||||
|
||||
var _set = function(player, params){
|
||||
var _set = function(params, player){
|
||||
var playerAliases = _store.players[player.name];
|
||||
if (!playerAliases){
|
||||
playerAliases = {};
|
||||
|
@ -92,11 +92,11 @@ var _set = function(player, params){
|
|||
player.sendMessage("Alias '" + o.cmd + "' created.");
|
||||
};
|
||||
|
||||
var _delete = function(player, params){
|
||||
var _remove = function(params, player){
|
||||
if (_store.players[player.name] &&
|
||||
_store.players[player.name][params[0]]){
|
||||
delete _store.players[player.name][params[0]];
|
||||
player.sendMessage("Alias '" + params[0] + "' deleted.");
|
||||
player.sendMessage("Alias '" + params[0] + "' removed.");
|
||||
}
|
||||
else{
|
||||
player.sendMessage("Alias '" + params[0] + "' does not exist.");
|
||||
|
@ -107,7 +107,7 @@ var _delete = function(player, params){
|
|||
}
|
||||
};
|
||||
|
||||
var _global = function(player, params){
|
||||
var _global = function(params, player){
|
||||
if (!player.op){
|
||||
player.sendMessage("Only operators can set global aliases. " +
|
||||
"You need to be an operator to perform this command.");
|
||||
|
@ -118,7 +118,7 @@ var _global = function(player, params){
|
|||
player.sendMessage("Global alias '" + o.cmd + "' created.");
|
||||
};
|
||||
|
||||
var _list = function(player){
|
||||
var _list = function(params, player){
|
||||
try {
|
||||
var alias = 0;
|
||||
if (_store.players[player.name]){
|
||||
|
@ -139,26 +139,42 @@ var _list = function(player){
|
|||
throw e;
|
||||
}
|
||||
};
|
||||
var _help = function(params, player){
|
||||
player.sendMessage('Usage:\n' + _usage);
|
||||
};
|
||||
var alias = plugin('alias', {
|
||||
"store": _store,
|
||||
"set": _set,
|
||||
"global": _global,
|
||||
"delete": _delete,
|
||||
"list": _list,
|
||||
"help": function(player){ player.sendMessage("Usage:\n" + _usage);}
|
||||
store: _store,
|
||||
set: _set,
|
||||
global: _global,
|
||||
remove: _remove,
|
||||
list: _list,
|
||||
help: _help
|
||||
}, true );
|
||||
|
||||
|
||||
var aliasCmd = command('alias', function(params,invoker){
|
||||
var operation = params[0];
|
||||
var aliasCmd = command('alias', function( params, invoker ) {
|
||||
var operation = params[0], fn;
|
||||
if (!operation){
|
||||
invoker.sendMessage("Usage:\n" + _usage);
|
||||
invoker.sendMessage('Usage:\n' + _usage);
|
||||
return;
|
||||
}
|
||||
if (alias[operation])
|
||||
alias[operation](invoker, params.slice(1));
|
||||
else
|
||||
invoker.sendMessage("Usage:\n" + _usage);
|
||||
/*
|
||||
wph 20140122 this is kind of dumb but Nashorn has some serious problems
|
||||
accessing object properties by array index notation
|
||||
in JRE8 alias[operation] returns null - definitely a bug in Nashorn.
|
||||
*/
|
||||
if (operation == 'set'){
|
||||
alias.set(params.slice(1), invoker);
|
||||
}else if (operation == 'global'){
|
||||
alias.global(params.slice(1), invoker);
|
||||
}else if (operation == 'remove'){
|
||||
alias.remove(params.slice(1), invoker);
|
||||
}else if (operation == 'list'){
|
||||
alias.list(params.slice(1), invoker);
|
||||
}else if (operation == 'help'){
|
||||
alias.help(params.slice(1), invoker);
|
||||
}else {
|
||||
invoker.sendMessage('Usage:\n' + _usage);
|
||||
}
|
||||
});
|
||||
|
||||
var _intercept = function( msg, invoker, exec)
|
||||
|
@ -177,7 +193,7 @@ var _intercept = function( msg, invoker, exec)
|
|||
if (config.verbose){
|
||||
var commandObj = server.commandMap.getCommand(command);
|
||||
if (!commandObj)
|
||||
console.info("No global alias found for command: " + command);
|
||||
console.info('No global alias found for command: ' + command);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
@ -192,7 +208,7 @@ var _intercept = function( msg, invoker, exec)
|
|||
if (config.verbose){
|
||||
var commandObj = server.commandMap.getCommand(command);
|
||||
if (!commandObj)
|
||||
console.info("No player alias found for command: " + command);
|
||||
console.info('No player alias found for command: ' + command);
|
||||
}
|
||||
}
|
||||
for (var i = 0;i < template.length; i++)
|
||||
|
@ -232,5 +248,5 @@ events.on('server.ServerCommandEvent', function(listener,evt){
|
|||
var exec = function(cmd){ invoker.server.dispatchCommand(invoker, cmd); };
|
||||
var isAlias = _intercept(''+evt.command, ''+ invoker.name, exec);
|
||||
if (isAlias)
|
||||
evt.command = "jsp void";
|
||||
evt.command = 'jsp void';
|
||||
});
|
||||
|
|
Reference in a new issue