mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-12-06 03:07:18 +00:00
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).
98 lines
3.6 KiB
Kotlin
98 lines
3.6 KiB
Kotlin
package plugin.commands
|
|
|
|
import com.rs2.event.EventContext
|
|
import com.rs2.event.EventSubscriber
|
|
import com.rs2.event.SubscribesTo
|
|
import com.rs2.event.impl.DeveloperCommandEvent
|
|
import com.rs2.game.npcs.NPCDefinition
|
|
import com.rs2.game.npcs.NpcHandler
|
|
import com.rs2.game.players.Player
|
|
|
|
@SubscribesTo(DeveloperCommandEvent::class)
|
|
class SpawnNpc : EventSubscriber<DeveloperCommandEvent> {
|
|
|
|
companion object {
|
|
/**
|
|
* Revision 377 maximum NPC ID (3,852 NPCs in cache: IDs 0..3851).
|
|
*/
|
|
private const val MAX_NPC_ID = 3851
|
|
|
|
private fun findNpcIdByName(name: String): Int {
|
|
var exact = -1
|
|
var prefix = -1
|
|
var substring = -1
|
|
for (id in 0..MAX_NPC_ID) {
|
|
try {
|
|
val def = NPCDefinition.forId(id) ?: continue
|
|
val defName = def.name ?: continue
|
|
if (defName.isEmpty() || defName.equals("null", ignoreCase = true) || defName.startsWith("NPC #")) continue
|
|
|
|
if (defName.equals(name, ignoreCase = true)) {
|
|
return id
|
|
}
|
|
if (prefix == -1 && defName.startsWith(name, ignoreCase = true)) {
|
|
prefix = id
|
|
} else if (prefix == -1 && substring == -1 && defName.contains(name, ignoreCase = true)) {
|
|
substring = id
|
|
}
|
|
} catch (ignored: Exception) {
|
|
continue
|
|
}
|
|
}
|
|
return when {
|
|
exact != -1 -> exact
|
|
prefix != -1 -> prefix
|
|
else -> substring
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun test(event: DeveloperCommandEvent): Boolean =
|
|
event.name.equals("spawnnpc", ignoreCase = true) || event.name.equals("npc", ignoreCase = true)
|
|
|
|
override fun subscribe(context: EventContext, player: Player?, event: DeveloperCommandEvent) {
|
|
if (player == null) return
|
|
|
|
context.breakSubscriberChain()
|
|
|
|
val arguments = event.arguments
|
|
if (arguments.isEmpty()) {
|
|
player.packetSender.sendMessage("You must specify an ID or name: ::spawnnpc 1000 or ::spawnnpc goblin")
|
|
return
|
|
}
|
|
|
|
val firstArgId = arguments[0].toIntOrNull()
|
|
val npcId = if (firstArgId != null) {
|
|
firstArgId
|
|
} else {
|
|
val npcName = arguments.joinToString(" ")
|
|
val resolvedId = findNpcIdByName(npcName)
|
|
if (resolvedId == -1) {
|
|
player.packetSender.sendMessage("No NPC found matching: $npcName")
|
|
return
|
|
}
|
|
resolvedId
|
|
}
|
|
|
|
if (npcId !in 0..MAX_NPC_ID) {
|
|
player.packetSender.sendMessage("No such NPC (ID: $npcId).")
|
|
return
|
|
}
|
|
|
|
val def = try { NPCDefinition.forId(npcId) } catch (e: Exception) { null }
|
|
val defName = def?.name
|
|
if (def == null || defName.isNullOrEmpty() || defName.equals("null", ignoreCase = true) || defName.startsWith("NPC #")) {
|
|
player.packetSender.sendMessage("No such NPC (ID: $npcId).")
|
|
return
|
|
}
|
|
|
|
val maxHit = NpcHandler.getNpcListCombat(npcId) / 10
|
|
val attack = NpcHandler.getNpcListCombat(npcId)
|
|
val defence = NpcHandler.getNpcListCombat(npcId)
|
|
val hp = NpcHandler.getNpcListHP(npcId).takeIf { it > 0 } ?: def.hitpoints.coerceAtLeast(1)
|
|
|
|
NpcHandler.spawnNpc(player, npcId, player.absX, player.absY, player.heightLevel, 0, hp, maxHit, attack, defence, false, false)
|
|
player.packetSender.sendMessage("You have spawned a $defName (ID: $npcId).")
|
|
}
|
|
}
|