Files
2006Scape/2006Scape Server/plugins/plugin/commands/Teleport.kt
T
Dark98 67147ef466 feat(commands): migrate item, npc, spellbook, and tele to plugins and add item/npc search
Migrate legacy hardcoded administrative and utility commands from Commands.java
to modular Kotlin event subscriber plugins, introduce dedicated item and NPC search
commands, and establish a permission-tiered command event hierarchy bounded by
Revision 377 cache specifications.

### Command Infrastructure
- CommandEvent.java:
  - Remove final modifier to allow permission-specific command event inheritance.
- ModeratorCommandEvent.java, AdminCommandEvent.java, DeveloperCommandEvent.java:
  - Add strongly typed event classes matching player permission tiers:
    Moderator (rights >= 1), Admin (rights >= 2), and Developer (rights == 3).
- Commands.java:
  - Dispatch permission-tiered command events across the event bus alongside switch handling.
  - Remove legacy switch implementations for ::item, ::npc, ::spellbook, and ::tele.

### Migrated Command Plugins
- SpawnItem.kt (::spawnitem, ::item):
  - Support both numeric IDs and fuzzy name resolution (exact, prefix, and substring).
  - Add quantity shorthand parsing for thousand (k), million (m), and billion (b) multipliers.
  - Support positional 'note' and 'noted' flags at the start or end of arguments; deprecate 'cert'.
  - Restrict valid IDs to Revision 377 cache bounds (0..7955).
  - Guard confirmation message against full inventory state when addItem() returns false.
- SpawnNpc.kt (::spawnnpc, ::npc):
  - Support both numeric IDs and fuzzy name resolution.
  - Validate against Revision 377 NPC ID range (0..3851), enabling ID 0 (Hans) spawning.
  - Calculate authentic combat, hitpoints, attack, and defence values with definitions fallback.
- Spellbook.kt (::spellbook):
  - Toggle between modern and ancient spellbooks when executed without arguments.
  - Support explicit 'modern'/'normal' and 'ancient'/'ancients' subcommands.
  - Cleanly reset autocast state via player.playerAssistant.resetAutocast().
- Teleport.kt (::teleport, ::tele):
  - Support coordinate teleportation with comma-tolerant token parsing (e.g. ::teleport 3222, 3218 0).
  - Add standard destination nicknames: lumby, fally, cammy, ardy, ape, and apeatoll.
  - Trigger authentic spell animations (modern 714/715, ancient 1979), graphics (308/392), and teleport sound effects.

### New Search Commands
- SearchItem.kt (::searchitem, ::itemsearch):
  - Search items by name or ID and render results on scrollable interface 8134.
  - Optimize interface clear range (8146..8195) to preserve title and subtitle lines without redundant packets.
  - Format output consistently in @bla@ with @dre@ noted tags and @blu@ ID labels.
  - Cap query scan at Revision 377 MAX_ITEM_ID (7955).
- SearchNpc.kt (::searchnpc, ::npcsearch):
  - Search NPCs by name or ID with scrollable interface 8134 display.
  - Format output in @bla@ with @yel@ combat levels and @blu@ ID labels.
  - Cap query scan at Revision 377 MAX_NPC_ID (3851).
2026-11-15 19:29:42 +00:00

131 lines
4.8 KiB
Kotlin

package plugin.commands
import com.rs2.Constants
import com.rs2.event.EventContext
import com.rs2.event.EventSubscriber
import com.rs2.event.SubscribesTo
import com.rs2.event.impl.AdminCommandEvent
import com.rs2.game.content.combat.magic.SpellTeleport
import com.rs2.game.content.music.sound.SoundList
import com.rs2.game.players.Player
@SubscribesTo(AdminCommandEvent::class)
class Teleport : EventSubscriber<AdminCommandEvent> {
companion object {
private const val ANIMATION_MODERN_START = 714
private const val ANIMATION_MODERN_END = 715
private const val GFX_MODERN = 308
private const val TIMER_MODERN = 10
private const val ANIMATION_ANCIENT_START = 1979
private const val GFX_ANCIENT = 392
private const val TIMER_ANCIENT = 9
private val CITIES = SpellTeleport.values().associateBy { it.name.lowercase().replace('_', ' ') }
private val CITY_ALIASES = mapOf(
"lumby" to "lumbridge",
"fally" to "falador",
"cammy" to "camelot",
"ardy" to "ardougne",
"ape" to "ape atoll",
"apeatoll" to "ape atoll"
)
private val VALID_CITIES_MESSAGES = listOf(
"Valid destinations:",
"Modern: varrock, lumbridge (lumby), falador (fally), camelot (cammy),",
" ardougne (ardy), watchtower, trollheim, ape atoll (ape)",
"Ancient: paddewwa, senntisten, kharyll, lassar,",
" dareeyak, carrallangar, annakarl, ghorrock"
)
}
override fun test(event: AdminCommandEvent): Boolean =
event.name.equals("teleport", ignoreCase = true) || event.name.equals("tele", ignoreCase = true)
override fun subscribe(context: EventContext, player: Player?, event: AdminCommandEvent) {
if (player == null) return
context.breakSubscriberChain()
val rawArguments = event.arguments
if (rawArguments.isEmpty()) {
player.packetSender.sendMessage("Usage: ::teleport <x> <y> [z] or ::teleport <city>")
player.packetSender.sendMessage("Examples: ::teleport 3222 3218 0 or ::teleport varrock")
return
}
val arguments = rawArguments.map { it.trimEnd(',') }
val x = arguments[0].toIntOrNull()
if (x == null) {
val normalized = arguments.joinToString(" ").lowercase().replace('_', ' ').replace('-', ' ').trim()
val resolvedCity = CITY_ALIASES[normalized] ?: normalized
val city = CITIES[resolvedCity]
if (city == null) {
player.packetSender.sendMessage("Unknown city '$normalized'.")
VALID_CITIES_MESSAGES.forEach { player.packetSender.sendMessage(it) }
return
}
val isAncient = city.type.equals("ancient", ignoreCase = true)
val displayName = city.name.lowercase().replace('_', ' ').split(" ").joinToString(" ") { it.replaceFirstChar(Char::titlecase) }
teleport(player, city.destX, city.destY, city.destZ, isAncient)
player.packetSender.sendMessage("Teleporting to $displayName...")
return
}
val y = arguments.getOrNull(1)?.toIntOrNull()
if (y == null) {
player.packetSender.sendMessage("Must specify coordinates: ::teleport <x> <y> [z]")
return
}
val z = arguments.getOrNull(2)?.toIntOrNull() ?: player.heightLevel
val isAncient = player.playerMagicBook == 1
teleport(player, x, y, z, isAncient)
player.packetSender.sendMessage("Teleporting to $x, $y${if (z != 0) ", $z" else ""}...")
}
private fun teleport(player: Player, x: Int, y: Int, z: Int, isAncient: Boolean) {
if (player.isDead || player.teleTimer > 0) return
with(player) {
if (playerIndex > 0 || npcIndex > 0) {
combatAssistant.resetPlayerAttack()
}
if (clickedTree) {
clickedTree = false
}
stopMovement()
packetSender.closeAllWindows()
teleX = x
teleY = y
npcIndex = 0
playerIndex = 0
faceUpdate(0)
refresh = heightLevel != z
teleHeight = z
isTeleporting = true
if (Constants.SOUND) {
packetSender.sendSound(SoundList.TELEPORT, 100, 700)
}
if (isAncient) {
startAnimation(ANIMATION_ANCIENT_START)
teleGfx = 0
teleTimer = TIMER_ANCIENT
teleEndAnimation = 0
gfx0(GFX_ANCIENT)
} else {
startAnimation(ANIMATION_MODERN_START, 10)
teleTimer = TIMER_MODERN
teleGfx = GFX_MODERN
teleEndAnimation = ANIMATION_MODERN_END
}
}
}
}