mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +00:00
Add input type checking to commands
This commit is contained in:
@@ -1,9 +1,17 @@
|
|||||||
|
import com.google.common.primitives.Ints
|
||||||
import org.apollo.game.model.Animation
|
import org.apollo.game.model.Animation
|
||||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||||
|
|
||||||
on_command("animate", PrivilegeLevel.MODERATOR)
|
on_command("animate", PrivilegeLevel.MODERATOR)
|
||||||
.then { player ->
|
.then { player ->
|
||||||
if(valid_arg_length(arguments, 1, player, "Invalid syntax - ::animate [animation-id]")) {
|
val invalidSyntax = "Invalid syntax - ::animate [animation-id]"
|
||||||
player.playAnimation(Animation(arguments[0].toInt()))
|
if(valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||||
|
val id = Ints.tryParse(arguments[0])
|
||||||
|
if (id == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
|
||||||
|
player.playAnimation(Animation(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,29 @@
|
|||||||
|
import com.google.common.primitives.Ints
|
||||||
import org.apollo.cache.def.ItemDefinition
|
import org.apollo.cache.def.ItemDefinition
|
||||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||||
|
|
||||||
on_command("item", PrivilegeLevel.ADMINISTRATOR)
|
on_command("item", PrivilegeLevel.ADMINISTRATOR)
|
||||||
.then { player ->
|
.then { player ->
|
||||||
if (!valid_arg_length(arguments, 1..2, player, "Invalid syntax - ::item [id] [amount]")) {
|
val invalidSyntax = "Invalid syntax - ::item [id] [amount]"
|
||||||
|
if (!valid_arg_length(arguments, 1..2, player, invalidSyntax)) {
|
||||||
return@then
|
return@then
|
||||||
}
|
}
|
||||||
|
|
||||||
val id = arguments[0].toInt()
|
val id = Ints.tryParse(arguments[0])
|
||||||
val amount = if (arguments.size == 2) arguments[1].toInt() else 1
|
if (id == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
|
||||||
|
var amount = 1
|
||||||
|
if (arguments.size == 2) {
|
||||||
|
val amt = Ints.tryParse(arguments[1])
|
||||||
|
if (amt == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
amount = amt
|
||||||
|
}
|
||||||
|
|
||||||
if (id < 0 || id >= ItemDefinition.count()) {
|
if (id < 0 || id >= ItemDefinition.count()) {
|
||||||
player.sendMessage("The item id you specified is out of bounds!")
|
player.sendMessage("The item id you specified is out of bounds!")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import com.google.common.primitives.Ints
|
||||||
import org.apollo.cache.def.ItemDefinition
|
import org.apollo.cache.def.ItemDefinition
|
||||||
import org.apollo.cache.def.NpcDefinition
|
import org.apollo.cache.def.NpcDefinition
|
||||||
import org.apollo.cache.def.ObjectDefinition
|
import org.apollo.cache.def.ObjectDefinition
|
||||||
@@ -5,11 +6,17 @@ import org.apollo.game.model.entity.setting.PrivilegeLevel
|
|||||||
|
|
||||||
on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR)
|
on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR)
|
||||||
.then { player ->
|
.then { player ->
|
||||||
if (!valid_arg_length(arguments, 1, player, "Invalid syntax - ::npcinfo [npc id]")) {
|
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
|
||||||
|
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
|
||||||
|
val id = Ints.tryParse(arguments[0])
|
||||||
|
if (id == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
return@then
|
return@then
|
||||||
}
|
}
|
||||||
|
|
||||||
val id = arguments[0].toInt()
|
|
||||||
val definition = ItemDefinition.lookup(id)
|
val definition = ItemDefinition.lookup(id)
|
||||||
val members = if (definition.isMembersOnly) "members" else "not members"
|
val members = if (definition.isMembersOnly) "members" else "not members"
|
||||||
|
|
||||||
@@ -20,11 +27,17 @@ on_command("iteminfo", PrivilegeLevel.ADMINISTRATOR)
|
|||||||
|
|
||||||
on_command("npcinfo", PrivilegeLevel.ADMINISTRATOR)
|
on_command("npcinfo", PrivilegeLevel.ADMINISTRATOR)
|
||||||
.then { player ->
|
.then { player ->
|
||||||
if (!valid_arg_length(arguments, 1, player, "Invalid syntax - ::npcinfo [npc id]")) {
|
val invalidSyntax = "Invalid syntax - ::npcinfo [npc id]"
|
||||||
|
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
|
||||||
|
val id = Ints.tryParse(arguments[0])
|
||||||
|
if (id == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
return@then
|
return@then
|
||||||
}
|
}
|
||||||
|
|
||||||
val id = arguments[0].toInt()
|
|
||||||
val definition = NpcDefinition.lookup(id)
|
val definition = NpcDefinition.lookup(id)
|
||||||
val isCombative = if (definition.hasCombatLevel()) "has a combat level of ${definition.combatLevel}" else
|
val isCombative = if (definition.hasCombatLevel()) "has a combat level of ${definition.combatLevel}" else
|
||||||
"does not have a combat level"
|
"does not have a combat level"
|
||||||
@@ -35,11 +48,17 @@ on_command("npcinfo", PrivilegeLevel.ADMINISTRATOR)
|
|||||||
|
|
||||||
on_command("objectinfo", PrivilegeLevel.ADMINISTRATOR)
|
on_command("objectinfo", PrivilegeLevel.ADMINISTRATOR)
|
||||||
.then { player ->
|
.then { player ->
|
||||||
if (!valid_arg_length(arguments, 1, player, "Invalid syntax - ::objectinfo [object id]")) {
|
val invalidSyntax = "Invalid syntax - ::objectinfo [object id]"
|
||||||
|
if (!valid_arg_length(arguments, 1, player, invalidSyntax)) {
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
|
||||||
|
val id = Ints.tryParse(arguments[0])
|
||||||
|
if (id == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
return@then
|
return@then
|
||||||
}
|
}
|
||||||
|
|
||||||
val id = arguments[0].toInt()
|
|
||||||
val definition = ObjectDefinition.lookup(id)
|
val definition = ObjectDefinition.lookup(id)
|
||||||
player.sendMessage("Object $id is called ${definition.name} and its description is " +
|
player.sendMessage("Object $id is called ${definition.name} and its description is " +
|
||||||
"\"${definition.description}\".")
|
"\"${definition.description}\".")
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
import com.google.common.primitives.Doubles
|
||||||
|
import com.google.common.primitives.Ints
|
||||||
import org.apollo.game.model.entity.Skill
|
import org.apollo.game.model.entity.Skill
|
||||||
import org.apollo.game.model.entity.SkillSet
|
import org.apollo.game.model.entity.SkillSet
|
||||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||||
@@ -26,8 +28,17 @@ on_command("level", PrivilegeLevel.ADMINISTRATOR)
|
|||||||
return@then
|
return@then
|
||||||
}
|
}
|
||||||
|
|
||||||
val skillId = arguments[0].toInt()
|
val skillId = Ints.tryParse(arguments[0])
|
||||||
val level = arguments[1].toInt()
|
if (skillId == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
val level = Ints.tryParse(arguments[1])
|
||||||
|
if (level == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
|
||||||
if (skillId !in 0..20 || level !in 1..99) {
|
if (skillId !in 0..20 || level !in 1..99) {
|
||||||
player.sendMessage(invalidSyntax)
|
player.sendMessage(invalidSyntax)
|
||||||
return@then
|
return@then
|
||||||
@@ -55,8 +66,17 @@ on_command("xp", PrivilegeLevel.ADMINISTRATOR)
|
|||||||
return@then
|
return@then
|
||||||
}
|
}
|
||||||
|
|
||||||
val skillId = arguments[0].toInt()
|
val skillId = Ints.tryParse(arguments[0])
|
||||||
val experience = arguments[1].toDouble()
|
if (skillId == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
val experience = Doubles.tryParse(arguments[1])
|
||||||
|
if (experience == null) {
|
||||||
|
player.sendMessage(invalidSyntax)
|
||||||
|
return@then
|
||||||
|
}
|
||||||
|
|
||||||
if (skillId !in 0..20 || experience <= 0) {
|
if (skillId !in 0..20 || experience <= 0) {
|
||||||
player.sendMessage("Invalid syntax - ::xp [skill-id] [experience]")
|
player.sendMessage("Invalid syntax - ::xp [skill-id] [experience]")
|
||||||
return@then
|
return@then
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import com.google.common.primitives.Ints
|
||||||
import org.apollo.game.model.Position
|
import org.apollo.game.model.Position
|
||||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||||
|
|
||||||
@@ -14,13 +15,32 @@ on_command("pos", PrivilegeLevel.MODERATOR)
|
|||||||
*/
|
*/
|
||||||
on_command("tele", PrivilegeLevel.ADMINISTRATOR)
|
on_command("tele", PrivilegeLevel.ADMINISTRATOR)
|
||||||
.then { player ->
|
.then { player ->
|
||||||
if (!valid_arg_length(arguments, 2..3, player, "Invalid syntax - ::tele [x] [y] [optional-z]")) {
|
val invalidSyntax = "Invalid syntax - ::tele [x] [y] [optional-z]"
|
||||||
|
if (!valid_arg_length(arguments, 2..3, player, invalidSyntax)) {
|
||||||
return@then
|
return@then
|
||||||
}
|
}
|
||||||
|
|
||||||
val x = arguments[0].toInt()
|
val x = Ints.tryParse(arguments[0])
|
||||||
val y = arguments[1].toInt()
|
if (x == null) {
|
||||||
val z = if (arguments.size == 3) arguments[2].toInt() else player.position.height
|
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) {
|
if (z in 0..4) {
|
||||||
player.teleport(Position(x, y, z))
|
player.teleport(Position(x, y, z))
|
||||||
|
|||||||
Reference in New Issue
Block a user