Fixes issue #179

This commit is contained in:
walterhiggins 2014-12-23 14:31:20 +00:00
parent ed863e460c
commit bba65fdfca
5 changed files with 21 additions and 12 deletions

View File

@ -1042,7 +1042,7 @@ The ScriptCraft console methods work like the [Web API implementation][webcons].
console.log('Hello %s', 'world');
Basic variable substitution is supported (ScriptCraft's implementation
of console uses the Bukkit Plugin [Logger][lgr] under the hood and
of console uses the Bukkit Plugin [Logger][lgr] or Canary Plugin [Logman][cmlgr] under the hood and
uses [java.lang.String.format()][strfmt] for variable
substitution. All output will be sent to the server console (not
in-game).
@ -1057,6 +1057,7 @@ ScriptCraft uses Java's [String.format()][strfmt] so any string substitution ide
}
[lgr]: http://jd.bukkit.org/beta/apidocs/org/bukkit/plugin/PluginLogger.html
[cmlgr]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/logger/Logman.html
[strfmt]: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...)
[webcons]: https://developer.mozilla.org/en-US/docs/Web/API/console

View File

@ -16,7 +16,7 @@ The ScriptCraft console methods work like the [Web API implementation][webcons].
console.log('Hello %s', 'world');
Basic variable substitution is supported (ScriptCraft's implementation
of console uses the Bukkit Plugin [Logger][lgr] under the hood and
of console uses the Bukkit Plugin [Logger][lgr] or Canary Plugin [Logman][cmlgr] under the hood and
uses [java.lang.String.format()][strfmt] for variable
substitution. All output will be sent to the server console (not
in-game).
@ -31,6 +31,7 @@ ScriptCraft uses Java's [String.format()][strfmt] so any string substitution ide
}
[lgr]: http://jd.bukkit.org/beta/apidocs/org/bukkit/plugin/PluginLogger.html
[cmlgr]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/logger/Logman.html
[strfmt]: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...)
[webcons]: https://developer.mozilla.org/en-US/docs/Web/API/console

View File

@ -1,5 +1,5 @@
'use strict';
/*global persist,exports,config,__plugin,require*/
var File = java.io.File,
FileWriter = java.io.FileWriter,
PrintWriter = java.io.PrintWriter;
@ -84,7 +84,8 @@ exports.autoload = function( context, pluginDir, logger, options ) {
}
} catch ( e ) {
if ( typeof logger != 'undefined' ) {
logger.error( 'Plugin ' + pluginPath + ' ' + e );
var msg = 'Plugin ' + pluginPath + ' ' + e ;
__plugin.canary ? logger.error( msg ) : logger.severe( msg );
} else {
java.lang.System.out.println( 'Error: Plugin ' + pluginPath + ' ' + e );
}

View File

@ -454,7 +454,7 @@ function __onEnable ( __engine, __plugin, __script ) {
}
result = JSON.parse(contents);
} catch ( e ) {
logger.error( 'Error evaluating ' + canonizedFilename + ', ' + e );
logError('Error evaluating ' + canonizedFilename + ', ' + e );
}
finally {
try {
@ -497,7 +497,7 @@ function __onEnable ( __engine, __plugin, __script ) {
result = __engine.eval( wrappedCode );
// issue #103 avoid side-effects of || operator on Mac Rhino
} catch ( e ) {
logger.error( 'Error evaluating ' + canonizedFilename + ', ' + e );
logError('Error evaluating ' + canonizedFilename + ', ' + e );
}
finally {
try {
@ -508,7 +508,7 @@ function __onEnable ( __engine, __plugin, __script ) {
}
} else {
if ( warnOnFileNotFound ) {
logger.warning( canonizedFilename + ' not found' );
logWarn(canonizedFilename + ' not found' );
}
}
return result;
@ -612,12 +612,12 @@ function __onEnable ( __engine, __plugin, __script ) {
echo(sender, JSON.stringify( jsResult, replacer, 2) );
}
} catch ( displayError ) {
logger.error( 'Error while trying to display result: ' + jsResult + ', Error: '+ displayError );
logError('Error while trying to display result: ' + jsResult + ', Error: '+ displayError) ;
}
}
}
} catch ( e ) {
logger.error( 'Error while trying to evaluate javascript: ' + fnBody + ', Error: '+ e );
logError( 'Error while trying to evaluate javascript: ' + fnBody + ', Error: '+ e );
echo( sender, 'Error while trying to evaluate javascript: ' + fnBody + ', Error: '+ e );
throw e;
} finally {
@ -650,7 +650,12 @@ function __onEnable ( __engine, __plugin, __script ) {
server = Bukkit.server;
logger = __plugin.logger;
}
function logError(msg){
__plugin.canary ? logger.error( msg ) : logger.severe( msg );
}
function logWarn(msg){
__plugin.canary ? logger.warn( msg ) : logger.warning( msg );
}
var File = java.io.File,
FileReader = java.io.FileReader,
BufferedReader = java.io.BufferedReader,

View File

@ -59,7 +59,7 @@ var __scboot = null;
*/
__scboot = function ( plugin, engine, classLoader )
{
var logger = plugin.logman,
var logger = plugin.canary ? plugin.logman : plugin.logger,
initScriptFile = new File(jsPlugins,initScript),
zips = ['lib','plugins','modules'],
i = 0,
@ -90,7 +90,8 @@ var __scboot = null;
engine.eval(new FileReader(initScriptFile));
__onEnable(engine, plugin, initScriptFile);
}catch ( e ){
logger.error('Error evaluating ' + initScriptFile + ': ' + e);
var msg = 'Error evaluating ' + initScriptFile + ': ' + e;
plugin.canary ? logger.error(msg) : logger.severe(msg);
throw e;
}
};