fix for issue #69

This commit is contained in:
walterhiggins 2013-03-09 16:50:12 +00:00
parent 6e113a2eca
commit 66abbfc142
3 changed files with 61 additions and 29 deletions

View file

@ -219,6 +219,19 @@ There are a couple of special javascript variables available in ScriptCraft...
* server - The Minecraft Server object. * server - The Minecraft Server object.
* self - the current player. (Note - this value should not be used in multi-threaded scripts - it's not thread-safe) * self - the current player. (Note - this value should not be used in multi-threaded scripts - it's not thread-safe)
refresh() function
------------------
The refresh() function will ...
1. Disable the ScriptCraft plugin.
2. Unload all event listeners associated with the ScriptCraft plugin.
3. Enable the ScriptCraft plugin.
... refresh() can be used during development to reload only scriptcraft javascript files.
See [issue #69][issue69] for more information.
[issue69]: https://github.com/walterhiggins/ScriptCraft/issues/69
Drone.spiral_stairs() method Drone.spiral_stairs() method
============================ ============================
Constructs a spiral staircase with slabs at each corner. Constructs a spiral staircase with slabs at each corner.

View file

@ -89,27 +89,24 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
public void onEnable() public void onEnable()
{ {
unzipJS(); unzipJS();
FileReader reader = null;
if (this.engine == null){ try{
FileReader reader = null; ScriptEngineManager factory = new ScriptEngineManager();
try{ File boot = new File(JS_PLUGINS_DIR + "/core/_scriptcraft.js");
ScriptEngineManager factory = new ScriptEngineManager(); this.engine = factory.getEngineByName("JavaScript");
File boot = new File(JS_PLUGINS_DIR + "/core/_scriptcraft.js"); this.engine.put("__engine",engine);
this.engine = factory.getEngineByName("JavaScript"); this.engine.put("__plugin",this);
this.engine.put("__engine",engine); this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/"));
this.engine.put("__plugin",this); reader = new FileReader(boot);
this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/")); this.engine.eval(reader);
reader = new FileReader(boot); }catch(Exception e){
this.engine.eval(reader); e.printStackTrace();
}catch(Exception e){ }finally {
e.printStackTrace(); if (reader != null){
}finally { try {
if (reader != null){ reader.close();
try { }catch(IOException ioe){
reader.close(); // fail silently
}catch(IOException ioe){
// fail silently
}
} }
} }
} }

View file

@ -640,17 +640,38 @@ var server = org.bukkit.Bukkit.server;
}; };
/* /*
Unload Handlers Unload Handlers
*/ */
var unloadHandlers = []; var unloadHandlers = [];
var _addUnloadHandler = function(f) { var _addUnloadHandler = function(f) {
unloadHandlers.push(f); unloadHandlers.push(f);
} };
var _runUnloadHandlers = function() { var _runUnloadHandlers = function() {
for (var i = 0; i < unloadHandlers.length; i++) { for (var i = 0; i < unloadHandlers.length; i++) {
unloadHandlers[i](); unloadHandlers[i]();
} }
} };
/*************************************************************************
refresh() function
------------------
The refresh() function will ...
1. Disable the ScriptCraft plugin.
2. Unload all event listeners associated with the ScriptCraft plugin.
3. Enable the ScriptCraft plugin.
... refresh() can be used during development to reload only scriptcraft javascript files.
See [issue #69][issue69] for more information.
[issue69]: https://github.com/walterhiggins/ScriptCraft/issues/69
***/
global.refresh = function(){
__plugin.pluginLoader.disablePlugin(__plugin);
forg.bukkit.event.HandlerList["unregisterAll(org.bukkit.plugin.Plugin)"](__plugin);
__plugin.pluginLoader.enablePlugin(__plugin);
};
global.load = _load; global.load = _load;
global.save = _save; global.save = _save;
@ -685,6 +706,7 @@ var server = org.bukkit.Bukkit.server;
_runUnloadHandlers(); _runUnloadHandlers();
}); });
}()); }());