Skip to content

Commit d27747b

Browse files
author
Martin P
committed
Fix refresh(): add skipOpCheck parameter, unregister event handlers & cancel tasks (only Bukkit)
1 parent badf8b5 commit d27747b

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/main/js/lib/scriptcraft.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,18 @@ The refresh() function can be used to only reload the ScriptCraft plugin (it's l
366366
367367
1. Disable the ScriptCraft plugin.
368368
2. Unload all event listeners associated with the ScriptCraft plugin.
369+
3. Cancel all timed tasks (created by `setInterval` & `setTimeout`)
369370
3. Enable the ScriptCraft plugin.
370371
371372
... refresh() can be used during development to reload only scriptcraft javascript files.
372373
See [issue #69][issue69] for more information.
373374
375+
By default, if `self` is defined at runtime, it checks, whether `self` is server operator, otherwise fails with message. This behavivor can be modified using `skipOpCheck` parameter (useful, if you are doing some custom premission checks before calling this function).
376+
377+
#### Parameters
378+
379+
* skipOpCheck (boolean - optional) : If true, the function won't check if `self` is server operator.
380+
374381
[issue69]: https://github.com/walterhiggins/ScriptCraft/issues/69
375382
376383
### addUnloadHandler() function
@@ -529,19 +536,20 @@ function __onEnable ( __engine, __plugin, __script ) {
529536
return sender.op;
530537
}
531538
}
532-
function _refresh( ) {
533-
if ( typeof self !== 'undefined' ) {
534-
if ( !_isOp(self) ) {
535-
echo( self, 'Only operators can refresh()');
536-
return;
537-
}
539+
function _refresh( skipOpCheck ) {
540+
if (!skipOpCheck && typeof self !== 'undefined') {
541+
if (!_isOp(self))
542+
return echo(self, 'Only operators can refresh()');
538543
}
544+
539545
if (__plugin.canary){
540546
var pluginName = __plugin.name;
541547
Canary.manager().disablePlugin( pluginName );
542548
Canary.manager().enablePlugin( pluginName );
543549
} else {
544550
__plugin.pluginLoader.disablePlugin( __plugin );
551+
org.bukkit.event.HandlerList["unregisterAll(org.bukkit.plugin.Plugin)"]( __plugin );
552+
server.scheduler.cancelTasks( __plugin );
545553
__plugin.pluginLoader.enablePlugin( __plugin );
546554
}
547555
} // end _refresh()

0 commit comments

Comments
 (0)