From 66abbfc14227558f62ffa32df938cafd9ccea882 Mon Sep 17 00:00:00 2001 From: walterhiggins Date: Sat, 9 Mar 2013 16:50:12 +0000 Subject: [PATCH] fix for issue #69 --- docs/api.md | 13 +++++++ .../scriptcraft/ScriptCraftPlugin.java | 39 +++++++++---------- src/main/javascript/core/_scriptcraft.js | 38 ++++++++++++++---- 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/docs/api.md b/docs/api.md index e9d4f18..36de6be 100644 --- a/docs/api.md +++ b/docs/api.md @@ -219,6 +219,19 @@ There are a couple of special javascript variables available in ScriptCraft... * 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) +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 ============================ Constructs a spiral staircase with slabs at each corner. diff --git a/src/main/java/net/walterhiggins/scriptcraft/ScriptCraftPlugin.java b/src/main/java/net/walterhiggins/scriptcraft/ScriptCraftPlugin.java index 16ee538..a68dae8 100644 --- a/src/main/java/net/walterhiggins/scriptcraft/ScriptCraftPlugin.java +++ b/src/main/java/net/walterhiggins/scriptcraft/ScriptCraftPlugin.java @@ -89,27 +89,24 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener public void onEnable() { unzipJS(); - - if (this.engine == null){ - FileReader reader = null; - try{ - ScriptEngineManager factory = new ScriptEngineManager(); - File boot = new File(JS_PLUGINS_DIR + "/core/_scriptcraft.js"); - this.engine = factory.getEngineByName("JavaScript"); - this.engine.put("__engine",engine); - this.engine.put("__plugin",this); - this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/")); - 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 - } + FileReader reader = null; + try{ + ScriptEngineManager factory = new ScriptEngineManager(); + File boot = new File(JS_PLUGINS_DIR + "/core/_scriptcraft.js"); + this.engine = factory.getEngineByName("JavaScript"); + this.engine.put("__engine",engine); + this.engine.put("__plugin",this); + this.engine.put("__script",boot.getCanonicalPath().replaceAll("\\\\","/")); + 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 } } } diff --git a/src/main/javascript/core/_scriptcraft.js b/src/main/javascript/core/_scriptcraft.js index 298f3ea..5e95067 100644 --- a/src/main/javascript/core/_scriptcraft.js +++ b/src/main/javascript/core/_scriptcraft.js @@ -640,17 +640,38 @@ var server = org.bukkit.Bukkit.server; }; /* - Unload Handlers - */ - var unloadHandlers = []; - var _addUnloadHandler = function(f) { + Unload Handlers + */ + var unloadHandlers = []; + var _addUnloadHandler = function(f) { unloadHandlers.push(f); - } - var _runUnloadHandlers = function() { + }; + var _runUnloadHandlers = function() { 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.save = _save; @@ -685,6 +706,7 @@ var server = org.bukkit.Bukkit.server; _runUnloadHandlers(); }); + }());