don't load same javascript file more than once

This commit is contained in:
walterhiggins 2013-01-24 20:12:41 +00:00
parent c5a096afaf
commit 844c70c21e
2 changed files with 17 additions and 28 deletions

View file

@ -42,33 +42,13 @@ var global = this;
if (typeof metadata == "undefined") if (typeof metadata == "undefined")
metadata = 0; metadata = 0;
var pl = org.bukkit.entity.Player;
var world = (__self instanceof org.bukkit.entity.Player)?__self.location.world:(__self instanceof org.bukkit.command.BlockCommandSender)?__self.block.location.world:null; var cs = org.bukkit.command.BlockCommandSender;
var world = (__self instanceof pl)?__self.location.world:(__self instanceof cs)?__self.block.location.world:null;
var block = world.getBlockAt(x,y,z); var block = world.getBlockAt(x,y,z);
/*
if (blockId === 6){
var treeType = null;
switch (metadata){
case 0:
treeType = org.bukkit.TreeType.BIG_TREE;
break;
case 1:
treeType = org.bukkit.TreeType.REDWOOD;
break;
case 2:
treeType = org.bukkit.TreeType.BIRCH;
break;
case 3:
treeType = org.bukkit.TreeType.JUNGLE;
break;
}
return world.generateTree(block.location,treeType);
}else{
*/
if (block.typeId != blockId || block.data != metadata) if (block.typeId != blockId || block.data != metadata)
block.setTypeIdAndData(blockId,metadata,false); block.setTypeIdAndData(blockId,metadata,false);
// }
}; };
var _putSign = function(texts, x, y, z, blockId, meta){ var _putSign = function(texts, x, y, z, blockId, meta){

View file

@ -38,6 +38,7 @@ var verbose = verbose || false;
var jsPluginsRootDirName = _canonize(jsPluginsRootDir); var jsPluginsRootDirName = _canonize(jsPluginsRootDir);
var _loaded = {};
/* /*
Load the contents of the file and evaluate as javascript Load the contents of the file and evaluate as javascript
*/ */
@ -45,8 +46,12 @@ var verbose = verbose || false;
{ {
var result = null; var result = null;
var file = new java.io.File(filename); var file = new java.io.File(filename);
var canonizedFilename = _canonize(file); var canonizedFilename = _canonize(file);
//
// wph 20130123 don't load the same file more than once.
//
if (_loaded[canonizedFilename])
return;
if (verbose) if (verbose)
print("loading " + canonizedFilename); print("loading " + canonizedFilename);
@ -58,6 +63,7 @@ var verbose = verbose || false;
__engine.put("__folder",(parent?_canonize(parent):"")+"/"); __engine.put("__folder",(parent?_canonize(parent):"")+"/");
try{ try{
result = __engine.eval(reader); result = __engine.eval(reader);
_loaded[canonizedFilename] = true;
}catch (e){ }catch (e){
__plugin.logger.severe("Error evaluating " + filename + ", " + e ); __plugin.logger.severe("Error evaluating " + filename + ", " + e );
} }
@ -95,6 +101,7 @@ var verbose = verbose || false;
*/ */
var _reload = function(pluginDir) var _reload = function(pluginDir)
{ {
_loaded = [];
var jsFiles = []; var jsFiles = [];
_listJsFiles(jsFiles,pluginDir); _listJsFiles(jsFiles,pluginDir);
// //
@ -107,9 +114,11 @@ var verbose = verbose || false;
// then it's assumed that _myMiniGame_currency.js and _myMiniGame_events.js will be loaded // then it's assumed that _myMiniGame_currency.js and _myMiniGame_events.js will be loaded
// as dependencies by myMiniGame.js and do not need to be loaded via js reload // as dependencies by myMiniGame.js and do not need to be loaded via js reload
// //
for (var i = 0;i < jsFiles.length; i++){ var len = jsFiles.length;
for (var i = 0;i < len; i++){
load(_canonize(jsFiles[i]),true); load(_canonize(jsFiles[i]),true);
} }
print("Loaded " + len + " javascript files");
}; };
/* /*