Remove 'world' object from global script scope

This commit is contained in:
Gary Tierney
2017-05-28 23:07:05 +01:00
parent 05e20d9d51
commit 48e1726bc0
7 changed files with 25 additions and 31 deletions
@@ -55,7 +55,7 @@ public class KotlinPluginEnvironment implements PluginEnvironment {
throw new RuntimeException(e);
}
pluginScripts.forEach(KotlinPluginScript::doStart);
pluginScripts.forEach(script -> script.doStart(world));
}
@Override
@@ -12,28 +12,28 @@ import kotlin.script.templates.ScriptTemplateDefinition
@ScriptTemplateDefinition(
scriptFilePattern = ".*\\.plugin\\.kts"
)
abstract class KotlinPluginScript(val world: World, val context: PluginContext) {
var startListener: () -> Unit = {};
var stopListener: () -> Unit = {};
abstract class KotlinPluginScript(private var world: World, val context: PluginContext) {
var startListener: (World) -> Unit = { _ -> };
var stopListener: (World) -> Unit = { _ -> };
protected fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
return KotlinMessageHandler(world, context, type.invoke())
}
protected fun start(callback: () -> Unit) {
protected fun start(callback: (World) -> Unit) {
this.startListener = callback
}
protected fun stop(callback: () -> Unit) {
protected fun stop(callback: (World) -> Unit) {
this.stopListener = callback
}
fun doStart() {
this.startListener.invoke()
fun doStart(world: World) {
this.startListener.invoke(world)
}
fun doStop() {
this.stopListener.invoke()
fun doStop(world: World) {
this.stopListener.invoke(world)
}
}