Simplify on_command arguments

This commit is contained in:
Cube
2017-06-03 15:23:03 +03:00
parent 30fc810d61
commit 8e8e2d0991
2 changed files with 5 additions and 5 deletions
@@ -67,19 +67,19 @@ class KotlinMessageHandler<T : Message>(val world: World, val context: PluginCon
} }
class KotlinCommandListener(val level: PrivilegeLevel, val function: (Player, Command) -> Unit) : CommandListener(level) { class KotlinCommandListener(val level: PrivilegeLevel, val function: Command.(Player) -> Unit) : CommandListener(level) {
override fun execute(player: Player, command: Command) { override fun execute(player: Player, command: Command) {
function.invoke(player, command) function.invoke(command, player)
} }
} }
class KotlinCommandHandler(val world : World, val command: String, val privileges: PrivilegeLevel) { class KotlinCommandHandler(val world : World, val command: String, val privileges: PrivilegeLevel) {
var function: (Player, Command) -> Unit = { _, _ -> } var function: Command.(Player) -> Unit = { _ -> }
fun then(function: (Player, Command) -> Unit) { fun then(function: Command.(Player) -> Unit) {
this.function = function this.function = function
world.commandDispatcher.register(command, KotlinCommandListener(privileges, function)) world.commandDispatcher.register(command, KotlinCommandListener(privileges, function))
} }
+1 -1
View File
@@ -2,4 +2,4 @@ import org.apollo.game.model.entity.setting.PrivilegeLevel
// Opens the player's bank if they are an administrator. // Opens the player's bank if they are an administrator.
on_command("bank", PrivilegeLevel.ADMINISTRATOR) on_command("bank", PrivilegeLevel.ADMINISTRATOR)
.then { player, _ -> player.openBank() } .then { player -> player.openBank() }