mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
Remove 'world' object from global script scope
This commit is contained in:
@@ -55,7 +55,7 @@ public class KotlinPluginEnvironment implements PluginEnvironment {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginScripts.forEach(KotlinPluginScript::doStart);
|
pluginScripts.forEach(script -> script.doStart(world));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -12,28 +12,28 @@ import kotlin.script.templates.ScriptTemplateDefinition
|
|||||||
@ScriptTemplateDefinition(
|
@ScriptTemplateDefinition(
|
||||||
scriptFilePattern = ".*\\.plugin\\.kts"
|
scriptFilePattern = ".*\\.plugin\\.kts"
|
||||||
)
|
)
|
||||||
abstract class KotlinPluginScript(val world: World, val context: PluginContext) {
|
abstract class KotlinPluginScript(private var world: World, val context: PluginContext) {
|
||||||
var startListener: () -> Unit = {};
|
var startListener: (World) -> Unit = { _ -> };
|
||||||
var stopListener: () -> Unit = {};
|
var stopListener: (World) -> Unit = { _ -> };
|
||||||
|
|
||||||
protected fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
|
protected fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
|
||||||
return KotlinMessageHandler(world, context, type.invoke())
|
return KotlinMessageHandler(world, context, type.invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun start(callback: () -> Unit) {
|
protected fun start(callback: (World) -> Unit) {
|
||||||
this.startListener = callback
|
this.startListener = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun stop(callback: () -> Unit) {
|
protected fun stop(callback: (World) -> Unit) {
|
||||||
this.stopListener = callback
|
this.stopListener = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doStart() {
|
fun doStart(world: World) {
|
||||||
this.startListener.invoke()
|
this.startListener.invoke(world)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doStop() {
|
fun doStop(world: World) {
|
||||||
this.stopListener.invoke()
|
this.stopListener.invoke(world)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ on { ObjectActionMessage::class }
|
|||||||
on { NpcActionMessage::class }
|
on { NpcActionMessage::class }
|
||||||
.where { option == 2 }
|
.where { option == 2 }
|
||||||
.then {
|
.then {
|
||||||
val npc = world.npcRepository[index]
|
val npc = it.world.npcRepository[index]
|
||||||
|
|
||||||
if (npc.id in BANKER_NPCS) {
|
if (npc.id in BANKER_NPCS) {
|
||||||
BankAction.start(this, it, npc.position)
|
BankAction.start(this, it, npc.position)
|
||||||
|
|||||||
@@ -3,21 +3,21 @@ import org.apollo.game.message.impl.SendFriendMessage
|
|||||||
import org.apollo.game.model.entity.setting.PrivacyState
|
import org.apollo.game.model.entity.setting.PrivacyState
|
||||||
|
|
||||||
on { AddFriendMessage::class }
|
on { AddFriendMessage::class }
|
||||||
.then { player ->
|
.then {
|
||||||
player.addFriend(username)
|
it.addFriend(username)
|
||||||
|
|
||||||
val playerUsername = player.username
|
val playerUsername = it.username
|
||||||
val friend = world.getPlayer(username)
|
val friend = it.world.getPlayer(username)
|
||||||
|
|
||||||
if (friend == null) {
|
if (friend == null) {
|
||||||
player.send(SendFriendMessage(username, 0))
|
it.send(SendFriendMessage(username, 0))
|
||||||
} else if (friend.friendsWith(playerUsername) || friend.friendPrivacy == PrivacyState.ON) {
|
} else if (friend.friendsWith(playerUsername) || friend.friendPrivacy == PrivacyState.ON) {
|
||||||
if (player.friendPrivacy != PrivacyState.OFF) {
|
if (it.friendPrivacy != PrivacyState.OFF) {
|
||||||
friend.send(SendFriendMessage(playerUsername, player.worldId))
|
friend.send(SendFriendMessage(playerUsername, it.worldId))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (friend.friendPrivacy != PrivacyState.OFF) {
|
if (friend.friendPrivacy != PrivacyState.OFF) {
|
||||||
player.send(SendFriendMessage(username, friend.worldId))
|
it.send(SendFriendMessage(username, friend.worldId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import org.apollo.game.message.impl.AddIgnoreMessage
|
|||||||
import org.apollo.game.message.impl.RemoveIgnoreMessage
|
import org.apollo.game.message.impl.RemoveIgnoreMessage
|
||||||
|
|
||||||
on { AddIgnoreMessage::class }
|
on { AddIgnoreMessage::class }
|
||||||
.then { player -> player.addIgnore(username) }
|
.then { it.addIgnore(username) }
|
||||||
|
|
||||||
on { RemoveIgnoreMessage::class }
|
on { RemoveIgnoreMessage::class }
|
||||||
.then { player -> player.removeIgnore(username) }
|
.then { it.removeIgnore(username) }
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import org.apollo.cache.def.NpcDefinition
|
import org.apollo.cache.def.NpcDefinition
|
||||||
import org.apollo.game.model.entity.Npc
|
import org.apollo.game.model.entity.Npc
|
||||||
|
|
||||||
start {
|
start { world ->
|
||||||
Spawns.list.forEach {
|
Spawns.list.forEach {
|
||||||
val definition = if (it.id != null) NpcDefinition.lookup(it.id) else lookup_npc(it.name)
|
val definition = if (it.id != null) NpcDefinition.lookup(it.id) else lookup_npc(it.name)
|
||||||
if (definition == null) {
|
if (definition == null) {
|
||||||
@@ -22,6 +22,3 @@ start {
|
|||||||
world.register(npc)
|
world.register(npc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stop {
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -12,17 +12,14 @@ import org.apollo.game.plugin.kotlin.*
|
|||||||
import org.apollo.net.message.Message
|
import org.apollo.net.message.Message
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
val world: World = null!!
|
|
||||||
var context: PluginContext = null!!
|
|
||||||
|
|
||||||
fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
|
fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
|
||||||
null!!
|
null!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun start(callback: () -> Unit) {
|
fun start(callback: (World) -> Unit) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop(callback: () -> Unit) {
|
fun stop(callback: (World) -> Unit) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user