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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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")){
|
||||||
} catch (IOException e) {
|
ScriptCraftEvaluator.loadJsFile(f,this.evaluator.ctx,this.evaluator.scope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}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"))
|
||||||
|
|
Reference in a new issue