Load files recursively from js-plugins dir
This commit is contained in:
parent
8dc32f46c9
commit
5710528467
1 changed files with 24 additions and 15 deletions
|
@ -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);
|
||||||
for (File f: files){
|
|
||||||
String canonicalPath = null;
|
|
||||||
try {
|
|
||||||
//
|
|
||||||
// fix for bug #11
|
|
||||||
//
|
|
||||||
canonicalPath = f.getCanonicalPath().replaceAll("\\\\", "/");
|
|
||||||
this.evaluator.eval("load(\"" + canonicalPath + "\")", null);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadJsPlugins (File directory){
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
for (File f: files){
|
||||||
|
String canonicalPath = null;
|
||||||
|
try {
|
||||||
|
this.getLogger().info("Loading javascript source file " + f);
|
||||||
|
if (f.isDirectory()){
|
||||||
|
loadJsPlugins(f);
|
||||||
|
}else{
|
||||||
|
//
|
||||||
|
// fix for bug #11
|
||||||
|
//
|
||||||
|
canonicalPath = f.getCanonicalPath().replaceAll("\\\\", "/");
|
||||||
|
if (canonicalPath.endsWith(".js")){
|
||||||
|
ScriptCraftEvaluator.loadJsFile(f,this.evaluator.ctx,this.evaluator.scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
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"))
|
||||||
|
|
Reference in a new issue