Remove command utilities plugin

This commit is contained in:
Major
2018-04-08 05:15:48 +01:00
parent 6e94f4c7d0
commit 275da1331b
8 changed files with 109 additions and 155 deletions
+1 -2
View File
@@ -7,7 +7,6 @@ plugin {
"cubeee",
]
dependencies = [
"api",
"util:command",
"api"
]
}
+6 -9
View File
@@ -1,18 +1,15 @@
import com.google.common.primitives.Ints
import org.apollo.game.model.Animation
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("animate", PrivilegeLevel.MODERATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::animate [animation-id]"
if (valid_arg_length(arguments, 1, player, invalidSyntax)) {
val id = Ints.tryParse(arguments[0])
if (id == null) {
player.sendMessage(invalidSyntax)
arguments.firstOrNull()
?.let(String::toIntOrNull)
?.let(::Animation)
?.let {
player.playAnimation(it)
return@then
}
player.playAnimation(Animation(id))
}
player.sendMessage("Invalid syntax - ::animate [animation-id]")
}
+10 -8
View File
@@ -1,29 +1,31 @@
import com.google.common.primitives.Ints
import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
on_command("item", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::item [id] [amount]"
if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) {
if (arguments.size !in 1..2) {
player.sendMessage("Invalid syntax - ::item [id] [amount]")
return@then
}
val id = Ints.tryParse(arguments[0])
if (id == null) {
player.sendMessage(invalidSyntax)
player.sendMessage("Invalid syntax - ::item [id] [amount]")
return@then
}
var amount = 1
if (arguments.size == 2) {
val amount = if (arguments.size == 2) {
val amt = Ints.tryParse(arguments[1])
if (amt == null) {
player.sendMessage(invalidSyntax)
player.sendMessage("Invalid syntax - ::item [id] [amount]")
return@then
}
amount = amt
amt
} else {
1
}
if (id < 0 || id >= ItemDefinition.count()) {
+32 -47
View File
@@ -1,67 +1,52 @@
import com.google.common.primitives.Ints
import org.apollo.cache.def.ItemDefinition
import org.apollo.cache.def.NpcDefinition
import org.apollo.cache.def.ObjectDefinition
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
import org.apollo.game.plugin.api.Definitions
on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
return@then
}
arguments.firstOrNull()
?.let(String::toIntOrNull)
?.let(Definitions::item)
?.apply {
val members = if (isMembersOnly) "members" else "not members"
val id = Ints.tryParse(arguments[0])
if (id == null) {
player.sendMessage(invalidSyntax)
return@then
}
player.sendMessage("Item $id is called $name and is $members only.")
player.sendMessage("Its description is `$description`.")
val definition = ItemDefinition.lookup(id)
val members = if (definition.isMembersOnly) "members" else "not members"
return@then
}
player.sendMessage("Item $id is called ${definition.name}, is $members only, and has a " +
"team of ${definition.team}.")
player.sendMessage("Its description is \"${definition.description}\".")
player.sendMessage("Invalid syntax - ::iteminfo [item id]")
}
on_command("npcinfo", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
return@then
arguments.firstOrNull()
?.let(String::toIntOrNull)
?.let(Definitions::npc)
?.apply {
val combat = if (hasCombatLevel()) "has a combat level of $combatLevel" else
"does not have a combat level"
player.sendMessage("Npc $id is called $name and $combat.")
player.sendMessage("Its description is `$description`.")
return@then
}
val id = Ints.tryParse(arguments[0])
if (id == null) {
player.sendMessage(invalidSyntax)
return@then
}
val definition = NpcDefinition.lookup(id)
val isCombative = if (definition.hasCombatLevel()) "has a combat level of ${definition.combatLevel}" else
"does not have a combat level"
player.sendMessage("Npc $id is called ${definition.name} and $isCombative.")
player.sendMessage("Its description is \"${definition.description}\".")
player.sendMessage("Invalid syntax - ::npcinfo [npc id]")
}
on_command("objectinfo", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::objectinfo [object id]"
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
return@then
}
arguments.firstOrNull()
?.let(String::toIntOrNull)
?.let(Definitions::obj)
?.apply {
player.sendMessage("Object ${arguments[0]} is called $name (width=$width, length=$length).")
player.sendMessage("Its description is `$description`.")
val id = Ints.tryParse(arguments[0])
if (id == null) {
player.sendMessage(invalidSyntax)
return@then
}
return@then
}
val definition = ObjectDefinition.lookup(id)
player.sendMessage("Object $id is called ${definition.name} and its description is " +
"\"${definition.description}\".")
player.sendMessage("Its width is ${definition.width} and its length is ${definition.length}.")
player.sendMessage("Invalid syntax - ::objectinfo [object id]")
}
+60 -63
View File
@@ -2,7 +2,6 @@
import com.google.common.primitives.Ints
import org.apollo.game.model.Position
import org.apollo.game.model.entity.setting.PrivilegeLevel
import org.apollo.game.plugin.util.command.valid_arg_length
import org.apollo.game.plugins.api.Position.component1
import org.apollo.game.plugins.api.Position.component2
import org.apollo.game.plugins.api.Position.component3
@@ -18,7 +17,65 @@ on_command("pos", PrivilegeLevel.MODERATOR)
player.sendMessage("You are at: ($x, $y, $z) in region (${region.x}, ${region.y}).")
}
val TELEPORT_DESTINATIONS = listOf(
/**
* Teleports the player to the specified position.
*/
on_command("tele", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z] or ::tele [place name]"
if (arguments.size == 1) {
val query = arguments[0]
val results = TELEPORT_DESTINATIONS.filter { (name) -> name.startsWith(query) }
if (results.isEmpty()) {
player.sendMessage("No destinations matching '$query'.")
return@then
} else if (results.size > 1) {
player.sendMessage("Ambiguous query '$query' (could be $results). Please disambiguate.")
return@then
}
val (name, dest) = results[0]
player.sendMessage("Teleporting to $name.")
player.teleport(dest)
return@then
}
if (arguments.size !in 2..3) {
player.sendMessage(invalidSyntax)
return@then
}
val x = Ints.tryParse(arguments[0])
if (x == null) {
player.sendMessage(invalidSyntax)
return@then
}
val y = Ints.tryParse(arguments[1])
if (y == null) {
player.sendMessage(invalidSyntax)
return@then
}
var z = player.position.height
if (arguments.size == 3) {
val plane = Ints.tryParse(arguments[2])
if (plane == null) {
player.sendMessage(invalidSyntax)
return@then
}
z = plane
}
if (z in 0..4) {
player.teleport(Position(x, y, z))
}
}
private val TELEPORT_DESTINATIONS = listOf(
"alkharid" to Position(3292, 3171, 0),
"ardougne" to Position(2662, 3304, 0),
"barrows" to Position(3565, 3314, 0),
@@ -49,64 +106,4 @@ val TELEPORT_DESTINATIONS = listOf(
"varrock" to Position(3212, 3423, 0),
"yanille" to Position(2605, 3096, 0),
"zanaris" to Position(2452, 4473, 0)
)
/**
* Teleports the player to the specified position.
*/
on_command("tele", PrivilegeLevel.ADMINISTRATOR)
.then { player ->
val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z] or ::tele [place name]"
if (arguments.size == 1) {
val query = arguments[0]
val results = TELEPORT_DESTINATIONS.filter {
(name, _) -> name.startsWith(query)
}
if (results.size == 0) {
player.sendMessage("No destinations matching '$query'.")
return@then
} else if (results.size > 1) {
player.sendMessage("Ambiguous query '$query' (could " +
"be $results). Please disambiguate.")
return@then
}
val (name, dest) = results[0]
player.sendMessage("Teleporting to $name.")
player.teleport(dest)
return@then
}
if (!valid_arg_length(arguments, 2..3, player, invalidSyntax)) {
return@then
}
val x = Ints.tryParse(arguments[0])
if (x == null) {
player.sendMessage(invalidSyntax)
return@then
}
val y = Ints.tryParse(arguments[1])
if (y == null) {
player.sendMessage(invalidSyntax)
return@then
}
var z = player.position.height
if (arguments.size == 3) {
val plane = Ints.tryParse(arguments[2])
if (plane == null) {
player.sendMessage(invalidSyntax)
return@then
}
z = plane
}
if (z in 0..4) {
player.teleport(Position(x, y, z))
}
}
)
@@ -5,7 +5,6 @@ plugin {
]
dependencies = [
"entity:walk-to",
"util:command",
"entity:player-action",
]
}
-3
View File
@@ -1,3 +0,0 @@
plugin {
name = "command_utilities"
}
-22
View File
@@ -1,22 +0,0 @@
package org.apollo.game.plugin.util.command
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: IntRange, player: Player, message: String): Boolean {
val valid = length.contains(args.size)
if (!valid) {
player.sendMessage(message)
}
return valid
}
/**
* 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: Int, player: Player, message: String)
= valid_arg_length(args, IntRange(length, length), player, message)