Convert ::animate command to Kotlin

This commit is contained in:
Cube
2017-06-03 18:55:40 +03:00
parent 8e8e2d0991
commit b99ee9ba31
4 changed files with 39 additions and 1 deletions
+6 -1
View File
@@ -1,6 +1,11 @@
name = "Chat commands"
package = "org.apollo.game.plugin.cmd"
authors = [ "Graham", "cubeee" ]
dependencies = [ "command_utilities" ]
authors = [
"Graham",
"Major",
"cubeee"
]
[config]
srcDir = "src/"
@@ -0,0 +1,9 @@
import org.apollo.game.model.Animation
import org.apollo.game.model.entity.setting.PrivilegeLevel
on_command("animate", PrivilegeLevel.MODERATOR)
.then { player ->
if(valid_arg_length(arguments, 1, player, "Invalid syntax - ::animate [animation-id]")) {
player.playAnimation(Animation(arguments[0].toInt()))
}
}
+5
View File
@@ -0,0 +1,5 @@
name = "command utilities"
package = "org.apollo.game.plugins.util"
[config]
srcDir = "src/"
@@ -0,0 +1,19 @@
import org.apollo.game.model.entity.Player
/**
* Checks whether the amount of arguments provided is correct, sending the player the specified
* message if not.
*/
fun valid_arg_length(args: Array<String>, length: Any, player: Player, message: String): Boolean {
val valid = when (length) {
is Int -> length == args.size
is IntRange -> length.contains(args.size)
else -> {
throw IllegalArgumentException("length must be one of the following: Int, IntRange")
}
}
if (!valid) {
player.sendMessage(message)
}
return valid
}