Fixed a bug in plugin code where stores were being trashed at startup

This commit is contained in:
walterhiggins 2013-12-25 07:48:10 +00:00
parent c6b600ae9f
commit d44a43e598
6 changed files with 35 additions and 46 deletions

View file

@ -1 +1,2 @@
bukkit-version=1.6.4 bukkit-version=1.7.2
scriptcraft-version=2.0

View file

@ -90,7 +90,7 @@
<!-- ensure plugin.yml is always copied --> <!-- ensure plugin.yml is always copied -->
<delete file="${build}/plugin.yml" /> <delete file="${build}/plugin.yml" />
<copy file="src/main/resources/plugin.yml" todir="${build}"/> <copy file="src/main/resources/plugin.yml" todir="${build}"/>
<replace file="${build}/plugin.yml" value="${bukkit-version}-${DSTAMP}"> <replace file="${build}/plugin.yml" value="${scriptcraft-version}-${DSTAMP}">
<replacetoken>[[version]]</replacetoken> <replacetoken>[[version]]</replacetoken>
</replace> </replace>

View file

@ -36,12 +36,13 @@ var _plugin = function(/* String */ moduleName, /* Object */ moduleObject, isPer
_plugins[moduleName] = pluginData; _plugins[moduleName] = pluginData;
if (isPersistent){ if (isPersistent){
if (!moduleObject.store){
moduleObject.store = {};
}
var loadedStore = load(dataDir.canonicalPath + "/" + moduleName + "-store.json"); var loadedStore = load(dataDir.canonicalPath + "/" + moduleName + "-store.json");
if (loadedStore){ if (loadedStore){
moduleObject.store = loadedStore; for (var i in loadedStore){
}else{ moduleObject.store[i] = loadedStore[i];
if (!moduleObject.store){
moduleObject.store = {};
} }
} }
} }

View file

@ -54,10 +54,12 @@ module specification, the '.js' suffix is optional.
[cjsmodules]: http://wiki.commonjs.org/wiki/Modules/1.1.1. [cjsmodules]: http://wiki.commonjs.org/wiki/Modules/1.1.1.
***/ ***/
( function (logger, evaluator, verbose, rootDir) { ( function (logger, evaluator, verbose, rootDir, modulePaths) {
if (verbose) if (verbose){
logger.info("Setting up 'require' module system. Root Directory: " + rootDir); logger.info("Setting up 'require' module system. Root Directory: " + rootDir);
logger.info("Module paths: " + JSON.stringify(modulePaths));
}
var File = java.io.File; var File = java.io.File;
@ -84,9 +86,6 @@ module specification, the '.js' suffix is optional.
} }
}; };
var LIB_DIR = rootDir + '/lib/';
var MODULE_DIR = rootDir + '/modules/';
var resolveModuleToFile = function(moduleName, parentDir) { var resolveModuleToFile = function(moduleName, parentDir) {
/********************************************************************** /**********************************************************************
## When resolving module names to file paths, ScriptCraft uses the following rules... ## When resolving module names to file paths, ScriptCraft uses the following rules...
@ -120,6 +119,7 @@ module specification, the '.js' suffix is optional.
3.2 if no package.json file exists then look for an index.js file in the directory 3.2 if no package.json file exists then look for an index.js file in the directory
***/ ***/
var file = new File(moduleName); var file = new File(moduleName);
var fileExists = function(file) { var fileExists = function(file) {
@ -137,41 +137,19 @@ module specification, the '.js' suffix is optional.
if (moduleName.match(/^[^\.\/]/)){ if (moduleName.match(/^[^\.\/]/)){
// it's a module named like so ... 'events' , 'net/http' // it's a module named like so ... 'events' , 'net/http'
// //
var resolvedFile;
var resolvedFile = new File(LIB_DIR + moduleName); for (var i = 0;i < modulePaths.length; i++){
if (resolvedFile.exists()){ resolvedFile = new File(modulePaths[i] + moduleName);
return fileExists(resolvedFile);
} else{
// try appending a .js to the end
resolvedFile = new File(LIB_DIR + moduleName + '.js');
if (resolvedFile.exists()){ if (resolvedFile.exists()){
return fileExists(resolvedFile);
return resolvedFile;
}else{ }else{
// try appending a .js to the end
if (verbose){ resolvedFile = new File(modulePaths[i] + moduleName + '.js');
logger.info("File not found in " + LIB_DIR + ': ' + resolvedFile.canonicalPath); if (resolvedFile.exists())
} return resolvedFile;
}
resolvedFile = new File(MODULE_DIR + moduleName); if (verbose){
if (resolvedFile.exists()){ logger.info("Module " + moduleName + " not found in " + modulePaths[i]);
return fileExists(resolvedFile);
}else {
if (verbose){
logger.info("File not found in " + MODULE_DIR + ': ' + resolvedFile.canonicalPath);
}
resolvedFile = new File(MODULE_DIR + moduleName + '.js');
if (resolvedFile.exists())
return resolvedFile;
else{
if (verbose){
logger.info("File not found in " + MODULE_DIR + ': ' + resolvedFile.canonicalPath);
}
}
}
} }
} }
} else { } else {

View file

@ -740,7 +740,16 @@ See [issue #69][issue69] for more information.
global.addUnloadHandler = _addUnloadHandler; global.addUnloadHandler = _addUnloadHandler;
var fnRequire = load(jsPluginsRootDirName + '/lib/require.js',true); var fnRequire = load(jsPluginsRootDirName + '/lib/require.js',true);
global.require = fnRequire(__plugin.logger, __engine, config.verbose, jsPluginsRootDirName); /*
setup paths to search for modules
*/
var modulePaths = [jsPluginsRootDirName + '/lib/',
jsPluginsRootDirName + '/modules/'];
global.require = fnRequire(__plugin.logger,
__engine,
config.verbose,
jsPluginsRootDirName,
modulePaths);
var plugins = require('plugin'); var plugins = require('plugin');

View file

@ -75,7 +75,7 @@ exports.classroom = classroom;
events.on('player.PlayerLoginEvent', function(listener, event) { events.on('player.PlayerLoginEvent', function(listener, event) {
var player = event.player; var player = event.player;
if (classroom.store.enableScripting){ if (_store.enableScripting){
player.addAttachment(__plugin, "scriptcraft.*", true); player.addAttachment(__plugin, "scriptcraft.*", true);
} }
}, "HIGHEST"); }, "HIGHEST");