Load files recursively from js-plugins dir

This commit is contained in:
walterhiggins 2013-01-06 20:04:40 +00:00
parent 8dc32f46c9
commit 5710528467

View file

@ -25,25 +25,34 @@ public class ScriptCraftPlugin extends JavaPlugin
String userDir = System.getProperty("user.dir"); String userDir = System.getProperty("user.dir");
File jsPlugins = new File(userDir + System.getProperty("file.separator") + "js-plugins"); File jsPlugins = new File(userDir + System.getProperty("file.separator") + "js-plugins");
if (jsPlugins.exists()){ if (jsPlugins.exists()){
File[] files = jsPlugins.listFiles(); loadJsPlugins(jsPlugins);
}
}
}
private void loadJsPlugins (File directory){
File[] files = directory.listFiles();
for (File f: files){ for (File f: files){
String canonicalPath = null; String canonicalPath = null;
try { try {
this.getLogger().info("Loading javascript source file " + f);
if (f.isDirectory()){
loadJsPlugins(f);
}else{
// //
// fix for bug #11 // fix for bug #11
// //
canonicalPath = f.getCanonicalPath().replaceAll("\\\\", "/"); canonicalPath = f.getCanonicalPath().replaceAll("\\\\", "/");
this.evaluator.eval("load(\"" + canonicalPath + "\")", null); if (canonicalPath.endsWith(".js")){
ScriptCraftEvaluator.loadJsFile(f,this.evaluator.ctx,this.evaluator.scope);
}
}
}catch(IOException e) { }catch(IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
}
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{ {
if(cmd.getName().equalsIgnoreCase("js")) if(cmd.getName().equalsIgnoreCase("js"))