fix for issue #69
This commit is contained in:
parent
6e113a2eca
commit
66abbfc142
3 changed files with 61 additions and 29 deletions
13
docs/api.md
13
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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
||||
}());
|
||||
|
||||
|
||||
|
|
Reference in a new issue