mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 00:38:46 +00:00
Add base for Kotlin commands
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
package org.apollo.game.plugin.kotlin
|
package org.apollo.game.plugin.kotlin
|
||||||
|
|
||||||
|
import org.apollo.game.command.Command
|
||||||
|
import org.apollo.game.command.CommandListener
|
||||||
import org.apollo.game.message.handler.MessageHandler
|
import org.apollo.game.message.handler.MessageHandler
|
||||||
import org.apollo.game.model.World
|
import org.apollo.game.model.World
|
||||||
import org.apollo.game.model.entity.Player
|
import org.apollo.game.model.entity.Player
|
||||||
|
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||||
import org.apollo.game.plugin.PluginContext
|
import org.apollo.game.plugin.PluginContext
|
||||||
import org.apollo.game.scheduling.ScheduledTask
|
|
||||||
import org.apollo.net.message.Message
|
import org.apollo.net.message.Message
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.script.templates.ScriptTemplateDefinition
|
import kotlin.script.templates.ScriptTemplateDefinition
|
||||||
@@ -20,6 +22,10 @@ abstract class KotlinPluginScript(private var world: World, val context: PluginC
|
|||||||
return KotlinMessageHandler(world, context, type.invoke())
|
return KotlinMessageHandler(world, context, type.invoke())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun on_command(command: String, privileges: PrivilegeLevel): KotlinCommandHandler {
|
||||||
|
return KotlinCommandHandler(world, command, privileges)
|
||||||
|
}
|
||||||
|
|
||||||
protected fun start(callback: (World) -> Unit) {
|
protected fun start(callback: (World) -> Unit) {
|
||||||
this.startListener = callback
|
this.startListener = callback
|
||||||
}
|
}
|
||||||
@@ -37,7 +43,6 @@ abstract class KotlinPluginScript(private var world: World, val context: PluginC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class KotlinMessageHandler<T : Message>(val world: World, val context: PluginContext, val type: KClass<T>) : MessageHandler<T>(world) {
|
class KotlinMessageHandler<T : Message>(val world: World, val context: PluginContext, val type: KClass<T>) : MessageHandler<T>(world) {
|
||||||
|
|
||||||
override fun handle(player: Player, message: T) {
|
override fun handle(player: Player, message: T) {
|
||||||
@@ -61,3 +66,22 @@ class KotlinMessageHandler<T : Message>(val world: World, val context: PluginCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class KotlinCommandListener(val level: PrivilegeLevel, val function: (Player, Command) -> Unit) : CommandListener(level) {
|
||||||
|
|
||||||
|
override fun execute(player: Player, command: Command) {
|
||||||
|
function.invoke(player, command)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class KotlinCommandHandler(val world : World, val command: String, val privileges: PrivilegeLevel) {
|
||||||
|
|
||||||
|
var function: (Player, Command) -> Unit = { _, _ -> }
|
||||||
|
|
||||||
|
fun then(function: (Player, Command) -> Unit) {
|
||||||
|
this.function = function
|
||||||
|
world.commandDispatcher.register(command, KotlinCommandListener(privileges, function))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apollo.game.model.World
|
import org.apollo.game.model.World
|
||||||
import org.apollo.game.plugin.PluginContext
|
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||||
import org.apollo.game.plugin.kotlin.*
|
import org.apollo.game.plugin.kotlin.KotlinCommandHandler
|
||||||
|
import org.apollo.game.plugin.kotlin.KotlinMessageHandler
|
||||||
import org.apollo.net.message.Message
|
import org.apollo.net.message.Message
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
@@ -16,6 +17,10 @@ fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
|
|||||||
null!!
|
null!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun on_command(command: String, privileges: PrivilegeLevel): KotlinCommandHandler {
|
||||||
|
null!!
|
||||||
|
}
|
||||||
|
|
||||||
fun start(callback: (World) -> Unit) {
|
fun start(callback: (World) -> Unit) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
name = "Chat commands"
|
||||||
|
package = "org.apollo.game.plugin.cmd"
|
||||||
|
authors = [ "Graham", "cubeee" ]
|
||||||
|
|
||||||
|
[config]
|
||||||
|
srcDir = "src/"
|
||||||
|
testDir = "test/"
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||||
|
|
||||||
|
// Opens the player's bank if they are an administrator.
|
||||||
|
on_command("bank", PrivilegeLevel.ADMINISTRATOR)
|
||||||
|
.then { player, _ -> player.openBank() }
|
||||||
@@ -16,6 +16,10 @@ fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
|
|||||||
null!!
|
null!!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun on_command(command: String, privileges: PrivilegeLevel): KotlinCommandHandler {
|
||||||
|
null!!
|
||||||
|
}
|
||||||
|
|
||||||
fun start(callback: (World) -> Unit) {
|
fun start(callback: (World) -> Unit) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user