Fix for issue #60 (files locked because the streamreader is not closed)
This commit is contained in:
parent
4336aa9d47
commit
8ce1de05ea
3 changed files with 17 additions and 2 deletions
|
@ -1,4 +1,6 @@
|
|||
import javax.script.*;
|
||||
import java.io.FileReader;
|
||||
|
||||
public class jscript
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
|
@ -8,6 +10,8 @@ public class jscript
|
|||
java.io.File file = new java.io.File(args[0]);
|
||||
engine.put("engine",engine);
|
||||
engine.put("args",args);
|
||||
engine.eval(new java.io.FileReader(file));
|
||||
FileReader fr = new java.io.FileReader(file);
|
||||
engine.eval(fr);
|
||||
fr.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ public class ScriptCraftPlugin extends JavaPlugin
|
|||
unzipJS();
|
||||
|
||||
if (this.engine == null){
|
||||
FileReader reader = null;
|
||||
try{
|
||||
ScriptEngineManager factory = new ScriptEngineManager();
|
||||
File boot = new File(JS_PLUGINS_DIR + "/core/_scriptcraft.js");
|
||||
|
@ -97,9 +98,18 @@ public class ScriptCraftPlugin extends JavaPlugin
|
|||
this.engine.put("__engine",engine);
|
||||
this.engine.put("__plugin",this);
|
||||
this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/"));
|
||||
this.engine.eval(new FileReader(boot));
|
||||
reader = new FileReader(boot);
|
||||
this.engine.eval(reader);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
if (reader != null){
|
||||
try {
|
||||
reader.close();
|
||||
}catch(IOException ioe){
|
||||
// fail silently
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -281,6 +281,7 @@ var server = org.bukkit.Bukkit.server;
|
|||
try{
|
||||
result = __engine.eval(reader);
|
||||
_loaded[canonizedFilename] = true;
|
||||
reader.close();
|
||||
}catch (e){
|
||||
__plugin.logger.severe("Error evaluating " + canonizedFilename + ", " + e );
|
||||
}
|
||||
|
|
Reference in a new issue