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
|
/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...
|
To get a list of aliases currently defined...
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@ var _cmdInterceptors = [];
|
||||||
*/
|
*/
|
||||||
var executeCmd = function(args, player){
|
var executeCmd = function(args, player){
|
||||||
if (args.length === 0)
|
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 name = args[0];
|
||||||
var cmd = _commands[name];
|
var cmd = _commands[name];
|
||||||
if (typeof cmd === "undefined"){
|
if (typeof cmd === 'undefined'){
|
||||||
// it's not a global command - pass it on to interceptors
|
// it's not a global command - pass it on to interceptors
|
||||||
var intercepted = false;
|
var intercepted = false;
|
||||||
for (var i = 0;i < _cmdInterceptors.length;i++){
|
for (var i = 0;i < _cmdInterceptors.length;i++){
|
||||||
|
@ -26,7 +26,7 @@ var executeCmd = function(args, player){
|
||||||
try {
|
try {
|
||||||
result = cmd.callback(args.slice(1),player);
|
result = cmd.callback(args.slice(1),player);
|
||||||
}catch (e){
|
}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;
|
throw e;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -36,16 +36,13 @@ var executeCmd = function(args, player){
|
||||||
define a new JSP command.
|
define a new JSP command.
|
||||||
*/
|
*/
|
||||||
var defineCmd = function(name, func, options, intercepts) {
|
var defineCmd = function(name, func, options, intercepts) {
|
||||||
if (typeof options == "undefined")
|
if (typeof options == 'undefined')
|
||||||
options = [];
|
options = [];
|
||||||
_commands[name] = {callback: func, options: options};
|
_commands[name] = {callback: func, options: options};
|
||||||
if (intercepts)
|
if (intercepts)
|
||||||
_cmdInterceptors.push(func);
|
_cmdInterceptors.push(func);
|
||||||
return func;
|
return func;
|
||||||
};
|
};
|
||||||
var _command = function(name, func, options, intercepts) {
|
exports.command = defineCmd;
|
||||||
return defineCmd(name, func, options, intercepts);
|
|
||||||
};
|
|
||||||
_command.exec = executeCmd;
|
|
||||||
exports.command = _command;
|
|
||||||
exports.commands = _commands;
|
exports.commands = _commands;
|
||||||
|
exports.exec = executeCmd;
|
||||||
|
|
|
@ -573,7 +573,8 @@ function __onEnable (__engine, __plugin, __script)
|
||||||
*/
|
*/
|
||||||
require('persistence')(jsPluginsRootDir,global);
|
require('persistence')(jsPluginsRootDir,global);
|
||||||
|
|
||||||
global.command = require('command').command;
|
var cmdModule = require('command');
|
||||||
|
global.command = cmdModule.command;
|
||||||
var plugins = require('plugin');
|
var plugins = require('plugin');
|
||||||
global.__onTabComplete = require('tabcomplete');
|
global.__onTabComplete = require('tabcomplete');
|
||||||
global.plugin = plugins.plugin;
|
global.plugin = plugins.plugin;
|
||||||
|
@ -593,7 +594,9 @@ function __onEnable (__engine, __plugin, __script)
|
||||||
global.__onCommand = function( sender, cmd, label, args) {
|
global.__onCommand = function( sender, cmd, label, args) {
|
||||||
var jsArgs = [];
|
var jsArgs = [];
|
||||||
var i = 0;
|
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 result = false;
|
||||||
var cmdName = ('' + cmd.name).toLowerCase();
|
var cmdName = ('' + cmd.name).toLowerCase();
|
||||||
|
@ -616,7 +619,7 @@ function __onEnable (__engine, __plugin, __script)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cmdName == 'jsp'){
|
if (cmdName == 'jsp'){
|
||||||
command.exec(jsArgs, sender);
|
cmdModule.exec(jsArgs, sender);
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -31,11 +31,11 @@ such an alias)...
|
||||||
|
|
||||||
/jsp alias global stormy = time 18000; weather storm
|
/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...
|
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 set {alias} = {comand-1} ;{command-2}\n \
|
||||||
/jsp alias global {alias} = {command-1} ; {command-2}\n \
|
/jsp alias global {alias} = {command-1} ; {command-2}\n \
|
||||||
/jsp alias list\n \
|
/jsp alias list\n \
|
||||||
/jsp alias delete {alias}\n \
|
/jsp alias remove {alias}\n \
|
||||||
Create a new alias : \n \
|
Create a new alias : \n \
|
||||||
/jsp alias set cw = time set {1} ; weather {2}\n \
|
/jsp alias set cw = time set {1} ; weather {2}\n \
|
||||||
Execute the alias : \n \
|
Execute the alias : \n \
|
||||||
|
@ -81,7 +81,7 @@ var _processParams = function(params){
|
||||||
return { cmd: aliasCmd, aliases: aliasValue.split(/\s*;\s*/) };
|
return { cmd: aliasCmd, aliases: aliasValue.split(/\s*;\s*/) };
|
||||||
};
|
};
|
||||||
|
|
||||||
var _set = function(player, params){
|
var _set = function(params, player){
|
||||||
var playerAliases = _store.players[player.name];
|
var playerAliases = _store.players[player.name];
|
||||||
if (!playerAliases){
|
if (!playerAliases){
|
||||||
playerAliases = {};
|
playerAliases = {};
|
||||||
|
@ -92,11 +92,11 @@ var _set = function(player, params){
|
||||||
player.sendMessage("Alias '" + o.cmd + "' created.");
|
player.sendMessage("Alias '" + o.cmd + "' created.");
|
||||||
};
|
};
|
||||||
|
|
||||||
var _delete = function(player, params){
|
var _remove = function(params, player){
|
||||||
if (_store.players[player.name] &&
|
if (_store.players[player.name] &&
|
||||||
_store.players[player.name][params[0]]){
|
_store.players[player.name][params[0]]){
|
||||||
delete _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{
|
else{
|
||||||
player.sendMessage("Alias '" + params[0] + "' does not exist.");
|
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){
|
if (!player.op){
|
||||||
player.sendMessage("Only operators can set global aliases. " +
|
player.sendMessage("Only operators can set global aliases. " +
|
||||||
"You need to be an operator to perform this command.");
|
"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.");
|
player.sendMessage("Global alias '" + o.cmd + "' created.");
|
||||||
};
|
};
|
||||||
|
|
||||||
var _list = function(player){
|
var _list = function(params, player){
|
||||||
try {
|
try {
|
||||||
var alias = 0;
|
var alias = 0;
|
||||||
if (_store.players[player.name]){
|
if (_store.players[player.name]){
|
||||||
|
@ -139,26 +139,42 @@ var _list = function(player){
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var _help = function(params, player){
|
||||||
|
player.sendMessage('Usage:\n' + _usage);
|
||||||
|
};
|
||||||
var alias = plugin('alias', {
|
var alias = plugin('alias', {
|
||||||
"store": _store,
|
store: _store,
|
||||||
"set": _set,
|
set: _set,
|
||||||
"global": _global,
|
global: _global,
|
||||||
"delete": _delete,
|
remove: _remove,
|
||||||
"list": _list,
|
list: _list,
|
||||||
"help": function(player){ player.sendMessage("Usage:\n" + _usage);}
|
help: _help
|
||||||
}, true );
|
}, true );
|
||||||
|
|
||||||
|
|
||||||
var aliasCmd = command('alias', function( params, invoker ) {
|
var aliasCmd = command('alias', function( params, invoker ) {
|
||||||
var operation = params[0];
|
var operation = params[0], fn;
|
||||||
if (!operation){
|
if (!operation){
|
||||||
invoker.sendMessage("Usage:\n" + _usage);
|
invoker.sendMessage('Usage:\n' + _usage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (alias[operation])
|
/*
|
||||||
alias[operation](invoker, params.slice(1));
|
wph 20140122 this is kind of dumb but Nashorn has some serious problems
|
||||||
else
|
accessing object properties by array index notation
|
||||||
invoker.sendMessage("Usage:\n" + _usage);
|
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)
|
var _intercept = function( msg, invoker, exec)
|
||||||
|
@ -177,7 +193,7 @@ var _intercept = function( msg, invoker, exec)
|
||||||
if (config.verbose){
|
if (config.verbose){
|
||||||
var commandObj = server.commandMap.getCommand(command);
|
var commandObj = server.commandMap.getCommand(command);
|
||||||
if (!commandObj)
|
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){
|
if (config.verbose){
|
||||||
var commandObj = server.commandMap.getCommand(command);
|
var commandObj = server.commandMap.getCommand(command);
|
||||||
if (!commandObj)
|
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++)
|
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 exec = function(cmd){ invoker.server.dispatchCommand(invoker, cmd); };
|
||||||
var isAlias = _intercept(''+evt.command, ''+ invoker.name, exec);
|
var isAlias = _intercept(''+evt.command, ''+ invoker.name, exec);
|
||||||
if (isAlias)
|
if (isAlias)
|
||||||
evt.command = "jsp void";
|
evt.command = 'jsp void';
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue