mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-12-05 19:01:04 +00:00
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).
This commit is contained in:
1 parent
e4c6fb3ed8
commit
67147ef466
11 files changed
+704
-79
No files matched your search
@@ -0,0 +1,99 @@
|
||||
package plugin.commands
|
||||
|
||||
import com.rs2.event.EventContext
|
||||
import com.rs2.event.EventSubscriber
|
||||
import com.rs2.event.SubscribesTo
|
||||
import com.rs2.event.impl.CommandEvent
|
||||
import com.rs2.game.players.Player
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
|
||||
@SubscribesTo(CommandEvent::class)
|
||||
class SearchItem : EventSubscriber<CommandEvent> {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Revision 377 maximum item ID (7,956 items in cache: IDs 0..7955).
|
||||
*/
|
||||
private const val MAX_ITEM_ID = 7955
|
||||
private const val INTERFACE_ID = 8134
|
||||
private const val TITLE_LINE_ID = 8144
|
||||
private const val SUBTITLE_LINE_ID = 8145
|
||||
private const val MAX_SCROLL_LINES = 199
|
||||
private val CLEAR_RANGES = arrayOf(8146..8195, 12174..12223, 14945..15044)
|
||||
|
||||
private fun showResults(player: Player, query: String, results: List<String>) {
|
||||
for (range in CLEAR_RANGES) {
|
||||
for (i in range) {
|
||||
player.packetSender.sendString("", i)
|
||||
}
|
||||
}
|
||||
|
||||
player.packetSender.sendString("@dre@Item Search: \"$query\"", TITLE_LINE_ID)
|
||||
|
||||
val total = results.size
|
||||
val subtitle = if (total > MAX_SCROLL_LINES) {
|
||||
"Showing first $MAX_SCROLL_LINES of $total matches (refine search for more)"
|
||||
} else {
|
||||
"$total match${if (total == 1) "" else "es"} found"
|
||||
}
|
||||
player.packetSender.sendString(subtitle, SUBTITLE_LINE_ID)
|
||||
|
||||
val display = results.take(MAX_SCROLL_LINES)
|
||||
for ((index, line) in display.withIndex()) {
|
||||
val lineId = when {
|
||||
index < 49 -> 8147 + index
|
||||
index < 99 -> 12174 + (index - 49)
|
||||
else -> 14945 + (index - 99)
|
||||
}
|
||||
player.packetSender.sendString(line, lineId)
|
||||
}
|
||||
|
||||
player.packetSender.showInterface(INTERFACE_ID)
|
||||
}
|
||||
}
|
||||
|
||||
override fun test(event: CommandEvent): Boolean = when (event.name.lowercase()) {
|
||||
"searchitem", "itemsearch" -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
override fun subscribe(context: EventContext, player: Player?, event: CommandEvent) {
|
||||
if (player == null) return
|
||||
|
||||
context.breakSubscriberChain()
|
||||
|
||||
val arguments = event.arguments
|
||||
if (arguments.isEmpty()) {
|
||||
player.packetSender.sendMessage("Specify an item name or ID to search: ::searchitem dragon or ::searchitem 4151")
|
||||
return
|
||||
}
|
||||
|
||||
val query = arguments.joinToString(" ").trim()
|
||||
val searchId = query.toIntOrNull()
|
||||
val count = ItemDefinition.count().coerceAtMost(MAX_ITEM_ID + 1)
|
||||
val notedId = if (searchId != null && searchId in 0 until count) ItemDefinition.itemToNote(searchId) else -1
|
||||
val unnotedId = if (searchId != null && searchId in 0 until count && ItemDefinition.lookup(searchId)?.isNote == true) {
|
||||
ItemDefinition.lookup(searchId)?.noteInfoId ?: -1
|
||||
} else -1
|
||||
val results = ArrayList<String>()
|
||||
|
||||
for (id in 0 until count) {
|
||||
val def = ItemDefinition.lookup(id) ?: continue
|
||||
val defName = def.name ?: continue
|
||||
if (defName.isEmpty() || defName.equals("null", ignoreCase = true)) continue
|
||||
|
||||
val matches = (searchId != null && (id == searchId || (notedId != searchId && id == notedId) || id == unnotedId))
|
||||
|| defName.contains(query, ignoreCase = true)
|
||||
if (matches) {
|
||||
val tag = if (def.isNote) " @dre@(noted)@bla@" else ""
|
||||
results.add("@bla@$defName$tag - ID: @blu@$id")
|
||||
}
|
||||
}
|
||||
|
||||
if (results.isEmpty()) {
|
||||
player.packetSender.sendMessage("No items found matching: $query")
|
||||
} else {
|
||||
showResults(player, query, results)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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.players.Player
|
||||
|
||||
@SubscribesTo(DeveloperCommandEvent::class)
|
||||
class SearchNpc : 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 const val INTERFACE_ID = 8134
|
||||
private const val TITLE_LINE_ID = 8144
|
||||
private const val SUBTITLE_LINE_ID = 8145
|
||||
private const val MAX_SCROLL_LINES = 199
|
||||
private val CLEAR_RANGES = arrayOf(8146..8195, 12174..12223, 14945..15044)
|
||||
|
||||
private fun showResults(player: Player, query: String, results: List<String>) {
|
||||
for (range in CLEAR_RANGES) {
|
||||
for (i in range) {
|
||||
player.packetSender.sendString("", i)
|
||||
}
|
||||
}
|
||||
|
||||
player.packetSender.sendString("@dre@NPC Search: \"$query\"", TITLE_LINE_ID)
|
||||
|
||||
val total = results.size
|
||||
val subtitle = if (total > MAX_SCROLL_LINES) {
|
||||
"Showing first $MAX_SCROLL_LINES of $total matches (refine search for more)"
|
||||
} else {
|
||||
"$total match${if (total == 1) "" else "es"} found"
|
||||
}
|
||||
player.packetSender.sendString(subtitle, SUBTITLE_LINE_ID)
|
||||
|
||||
val display = results.take(MAX_SCROLL_LINES)
|
||||
for ((index, line) in display.withIndex()) {
|
||||
val lineId = when {
|
||||
index < 49 -> 8147 + index
|
||||
index < 99 -> 12174 + (index - 49)
|
||||
else -> 14945 + (index - 99)
|
||||
}
|
||||
player.packetSender.sendString(line, lineId)
|
||||
}
|
||||
|
||||
player.packetSender.showInterface(INTERFACE_ID)
|
||||
}
|
||||
}
|
||||
|
||||
override fun test(event: DeveloperCommandEvent): Boolean = when (event.name.lowercase()) {
|
||||
"searchnpc", "npcsearch" -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
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("Specify an NPC name or ID to search: ::searchnpc goblin or ::searchnpc 9")
|
||||
return
|
||||
}
|
||||
|
||||
val query = arguments.joinToString(" ").trim()
|
||||
val searchId = query.toIntOrNull()
|
||||
val results = ArrayList<String>()
|
||||
|
||||
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
|
||||
|
||||
val matches = (searchId != null && id == searchId) || defName.contains(query, ignoreCase = true)
|
||||
if (matches) {
|
||||
val combatTag = if (def.combat > 0) " @yel@(Level: ${def.combat})@bla@" else ""
|
||||
results.add("@bla@$defName$combatTag - ID: @blu@$id")
|
||||
}
|
||||
} catch (ignored: Exception) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (results.isEmpty()) {
|
||||
player.packetSender.sendMessage("No NPCs found matching: $query")
|
||||
} else {
|
||||
showResults(player, query, results)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
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.players.Player
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import java.text.NumberFormat
|
||||
|
||||
@SubscribesTo(DeveloperCommandEvent::class)
|
||||
class SpawnItem : EventSubscriber<DeveloperCommandEvent> {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Revision 377 maximum item ID (7,956 items in cache: IDs 0..7955).
|
||||
*/
|
||||
private const val MAX_ITEM_ID = 7955
|
||||
|
||||
private fun parseAmount(str: String): Int? {
|
||||
val clean = str.trim().lowercase()
|
||||
if (clean.isEmpty()) return null
|
||||
|
||||
val multiplier = when {
|
||||
clean.endsWith("b") -> 1_000_000_000L
|
||||
clean.endsWith("m") -> 1_000_000L
|
||||
clean.endsWith("k") -> 1_000L
|
||||
else -> 1L
|
||||
}
|
||||
|
||||
val numPart = if (multiplier > 1L) clean.dropLast(1) else clean
|
||||
val num = numPart.toDoubleOrNull() ?: return null
|
||||
if (num <= 0.0) return null
|
||||
|
||||
val total = (num * multiplier).toLong()
|
||||
return total.coerceIn(1L, Int.MAX_VALUE.toLong()).toInt()
|
||||
}
|
||||
|
||||
private fun findItemIdByName(name: String): Int {
|
||||
var exact = -1
|
||||
var prefix = -1
|
||||
var substring = -1
|
||||
val count = ItemDefinition.count().coerceAtMost(MAX_ITEM_ID + 1)
|
||||
for (id in 0 until count) {
|
||||
val def = ItemDefinition.lookup(id) ?: continue
|
||||
val defName = def.name ?: continue
|
||||
if (defName.isEmpty() || defName.equals("null", ignoreCase = true)) continue
|
||||
|
||||
if (defName.equals(name, ignoreCase = true)) {
|
||||
if (!def.isNote) return id
|
||||
if (exact == -1) exact = id
|
||||
} else if (exact == -1) {
|
||||
if (defName.startsWith(name, ignoreCase = true)) {
|
||||
if (prefix == -1 || (ItemDefinition.lookup(prefix)?.isNote == true && !def.isNote)) {
|
||||
prefix = id
|
||||
}
|
||||
} else if (prefix == -1 && defName.contains(name, ignoreCase = true)) {
|
||||
if (substring == -1 || (ItemDefinition.lookup(substring)?.isNote == true && !def.isNote)) {
|
||||
substring = id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return when {
|
||||
exact != -1 -> exact
|
||||
prefix != -1 -> prefix
|
||||
else -> substring
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun test(event: DeveloperCommandEvent): Boolean =
|
||||
event.name.equals("spawnitem", ignoreCase = true) || event.name.equals("item", 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("Must specify an item id or name: ::spawnitem 995 10m, ::spawnitem coins 100k, or ::spawnitem noted gold ore 10m")
|
||||
return
|
||||
}
|
||||
|
||||
val tokens = arguments.toMutableList()
|
||||
var requestedNote = false
|
||||
if (tokens.isNotEmpty() && (tokens.first().equals("noted", ignoreCase = true) || tokens.first().equals("note", ignoreCase = true))) {
|
||||
requestedNote = true
|
||||
tokens.removeAt(0)
|
||||
} else if (tokens.isNotEmpty() && (tokens.last().equals("noted", ignoreCase = true) || tokens.last().equals("note", ignoreCase = true))) {
|
||||
requestedNote = true
|
||||
tokens.removeAt(tokens.size - 1)
|
||||
}
|
||||
|
||||
if (tokens.isEmpty()) {
|
||||
player.packetSender.sendMessage("Must specify an item id or name: ::spawnitem noted gold ore 10m")
|
||||
return
|
||||
}
|
||||
|
||||
val firstArgId = tokens[0].toIntOrNull()
|
||||
var itemId: Int
|
||||
val itemAmount: Int
|
||||
|
||||
if (firstArgId != null) {
|
||||
itemId = firstArgId
|
||||
if (tokens.size >= 2) {
|
||||
val parsed = parseAmount(tokens[1])
|
||||
if (parsed == null) {
|
||||
player.packetSender.sendMessage("Invalid amount specified: ${tokens[1]}")
|
||||
return
|
||||
}
|
||||
itemAmount = parsed
|
||||
} else {
|
||||
itemAmount = 1
|
||||
}
|
||||
} else {
|
||||
var amount = 1
|
||||
var nameTokens = tokens.toList()
|
||||
if (tokens.size >= 2) {
|
||||
val trailingAmount = parseAmount(tokens.last())
|
||||
if (trailingAmount != null) {
|
||||
amount = trailingAmount
|
||||
nameTokens = tokens.subList(0, tokens.size - 1)
|
||||
}
|
||||
}
|
||||
val itemName = nameTokens.joinToString(" ")
|
||||
val resolvedId = findItemIdByName(itemName)
|
||||
if (resolvedId == -1) {
|
||||
player.packetSender.sendMessage("No item found matching: $itemName")
|
||||
return
|
||||
}
|
||||
itemId = resolvedId
|
||||
itemAmount = amount
|
||||
}
|
||||
|
||||
if (itemId !in 0..MAX_ITEM_ID || itemId >= ItemDefinition.count()) {
|
||||
player.packetSender.sendMessage("No such item (ID: $itemId).")
|
||||
return
|
||||
}
|
||||
|
||||
var def = ItemDefinition.lookup(itemId)
|
||||
val defName = def?.name
|
||||
if (def == null || defName.isNullOrEmpty() || defName.equals("null", ignoreCase = true)) {
|
||||
player.packetSender.sendMessage("No such item (ID: $itemId).")
|
||||
return
|
||||
}
|
||||
|
||||
if (requestedNote) {
|
||||
val notedId = ItemDefinition.itemToNote(itemId)
|
||||
if (notedId == itemId) {
|
||||
if (!def.isNote) {
|
||||
player.packetSender.sendMessage("Note: $defName cannot be noted.")
|
||||
}
|
||||
} else {
|
||||
itemId = notedId
|
||||
def = ItemDefinition.lookup(notedId) ?: def
|
||||
}
|
||||
}
|
||||
|
||||
val added = player.itemAssistant.addItem(itemId, itemAmount)
|
||||
if (!added) {
|
||||
return
|
||||
}
|
||||
|
||||
if (player.isBusy) {
|
||||
player.packetSender.closeAllWindows()
|
||||
}
|
||||
|
||||
val formattedAmount = NumberFormat.getIntegerInstance().format(itemAmount)
|
||||
val noteTag = if (def.isNote) " (noted)" else ""
|
||||
player.packetSender.sendMessage("You have spawned $formattedAmount x $defName$noteTag (ID: $itemId).")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
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).")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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.players.Player
|
||||
|
||||
@SubscribesTo(DeveloperCommandEvent::class)
|
||||
class Spellbook : EventSubscriber<DeveloperCommandEvent> {
|
||||
|
||||
override fun test(event: DeveloperCommandEvent): Boolean =
|
||||
event.name.equals("spellbook", ignoreCase = true)
|
||||
|
||||
override fun subscribe(context: EventContext, player: Player?, event: DeveloperCommandEvent) {
|
||||
if (player == null) return
|
||||
|
||||
context.breakSubscriberChain()
|
||||
|
||||
val arguments = event.arguments
|
||||
val toModern = if (arguments.isEmpty()) {
|
||||
player.playerMagicBook == 1
|
||||
} else {
|
||||
when (arguments[0].lowercase()) {
|
||||
"modern", "normal" -> true
|
||||
"ancient", "ancients" -> false
|
||||
else -> {
|
||||
player.packetSender.sendMessage("Usage: ::spellbook [modern|ancient]")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toModern) {
|
||||
if (player.playerMagicBook == 0) {
|
||||
player.packetSender.sendMessage("You are already on the modern spellbook.")
|
||||
return
|
||||
}
|
||||
player.packetSender.setSidebarInterface(6, 1151)
|
||||
player.playerMagicBook = 0
|
||||
player.packetSender.sendMessage("You feel a drain on your memory.")
|
||||
player.playerAssistant.resetAutocast()
|
||||
} else {
|
||||
if (player.playerMagicBook == 1) {
|
||||
player.packetSender.sendMessage("You are already on the ancient spellbook.")
|
||||
return
|
||||
}
|
||||
player.playerMagicBook = 1
|
||||
player.packetSender.setSidebarInterface(6, 12855)
|
||||
player.packetSender.sendMessage("An ancient wisdom fills your mind.")
|
||||
player.playerAssistant.resetAutocast()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.rs2.event.impl;
|
||||
|
||||
/**
|
||||
* Represents an administrator command event.
|
||||
*/
|
||||
public class AdminCommandEvent extends CommandEvent {
|
||||
|
||||
public AdminCommandEvent(String name, String input) {
|
||||
super(name, input);
|
||||
}
|
||||
|
||||
public AdminCommandEvent(String name, String input, String[] arguments) {
|
||||
super(name, input, arguments);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import com.rs2.event.Event;
|
||||
*
|
||||
* @author Vult-R
|
||||
*/
|
||||
public final class CommandEvent implements Event {
|
||||
public class CommandEvent implements Event {
|
||||
|
||||
/**
|
||||
* The name for this command.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.rs2.event.impl;
|
||||
|
||||
/**
|
||||
* Represents a developer command event.
|
||||
*/
|
||||
public class DeveloperCommandEvent extends CommandEvent {
|
||||
|
||||
public DeveloperCommandEvent(String name, String input) {
|
||||
super(name, input);
|
||||
}
|
||||
|
||||
public DeveloperCommandEvent(String name, String input, String[] arguments) {
|
||||
super(name, input, arguments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.rs2.event.impl;
|
||||
|
||||
/**
|
||||
* Represents a moderator command event.
|
||||
*/
|
||||
public class ModeratorCommandEvent extends CommandEvent {
|
||||
|
||||
public ModeratorCommandEvent(String name, String input) {
|
||||
super(name, input);
|
||||
}
|
||||
|
||||
public ModeratorCommandEvent(String name, String input, String[] arguments) {
|
||||
super(name, input, arguments);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,10 @@ import java.util.*;
|
||||
import com.rs2.Connection;
|
||||
import com.rs2.Constants;
|
||||
import com.rs2.GameEngine;
|
||||
import com.rs2.event.impl.AdminCommandEvent;
|
||||
import com.rs2.event.impl.CommandEvent;
|
||||
import com.rs2.event.impl.DeveloperCommandEvent;
|
||||
import com.rs2.event.impl.ModeratorCommandEvent;
|
||||
import com.rs2.game.bots.BotHandler;
|
||||
import com.rs2.game.npcs.NPCDefinition;
|
||||
import com.rs2.game.npcs.NpcHandler;
|
||||
@@ -31,22 +34,24 @@ public class Commands implements PacketType {
|
||||
String playerCommand = messageArr[0];
|
||||
String[] commandArguments = Arrays.copyOfRange(messageArr, 1, messageArr.length);
|
||||
|
||||
player.post(new CommandEvent(playerCommand, fullPacket, commandArguments));
|
||||
|
||||
if ((playerCommand.startsWith("ban") || playerCommand.startsWith("ip") || playerCommand.startsWith("mute") || playerCommand.startsWith("un")) && player.playerRights > 0 && player.playerRights < 4) {
|
||||
writeLog(player.playerName, "commands", player.playerName + " used command: " + playerCommand);
|
||||
}
|
||||
if (player.playerRights >= 0) {
|
||||
playerCommands(player, playerCommand, commandArguments);
|
||||
player.post(new CommandEvent(playerCommand, fullPacket, commandArguments));
|
||||
}
|
||||
if (player.playerRights >= 1) {
|
||||
moderatorCommands(player, playerCommand, commandArguments);
|
||||
player.post(new ModeratorCommandEvent(playerCommand, fullPacket, commandArguments));
|
||||
}
|
||||
if (player.playerRights >= 2 && player.playerRights < 4) {
|
||||
adminCommands(player, playerCommand, commandArguments);
|
||||
player.post(new AdminCommandEvent(playerCommand, fullPacket, commandArguments));
|
||||
}
|
||||
if (player.playerRights == 3) {
|
||||
developerCommands(player, playerCommand, commandArguments);
|
||||
player.post(new DeveloperCommandEvent(playerCommand, fullPacket, commandArguments));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,24 +391,6 @@ public class Commands implements PacketType {
|
||||
case "uptime":
|
||||
player.getPacketSender().sendMessage("The server has now been online for: " + Misc.getServerUptime(GameEngine.getServerStartTime()));
|
||||
break;
|
||||
case "tele":
|
||||
if (player.connectedFrom.equals("127.0.0.1")) {
|
||||
try {
|
||||
if (arguments.length < 2) {
|
||||
player.getPacketSender().sendMessage("Must specify x, y and optionally z coordinates: ::tele 3222 3218 0");
|
||||
return;
|
||||
}
|
||||
if (arguments.length == 3)
|
||||
player.getPlayerAssistant().movePlayer(Integer.parseInt(arguments[0]), Integer.parseInt(arguments[1]), Integer.parseInt(arguments[2]));
|
||||
else
|
||||
player.getPlayerAssistant().movePlayer(Integer.parseInt(arguments[0]), Integer.parseInt(arguments[1]), player.heightLevel);
|
||||
} catch (Exception e) {
|
||||
player.getPacketSender().sendMessage("Invalid coordinates");
|
||||
}
|
||||
} else {
|
||||
player.getPacketSender().sendMessage("Can't tele with ip " + player.connectedFrom);
|
||||
}
|
||||
break;
|
||||
case "close_interface":
|
||||
player.getPacketSender().closeAllWindows();
|
||||
break;
|
||||
@@ -921,43 +908,6 @@ public class Commands implements PacketType {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
break;
|
||||
case "spellbook":
|
||||
if (player.inWild()) {
|
||||
return;
|
||||
}
|
||||
if (player.playerMagicBook == 0) {
|
||||
player.playerMagicBook = 1;
|
||||
player.getPacketSender().setSidebarInterface(6, 12855);
|
||||
player.getPacketSender().sendMessage("An ancient wisdomin fills your mind.");
|
||||
player.getPlayerAssistant().resetAutocast();
|
||||
} else if (player.playerMagicBook == 1) {
|
||||
player.getPacketSender().setSidebarInterface(6, 1151); // modern
|
||||
player.playerMagicBook = 0;
|
||||
player.getPacketSender().sendMessage("You feel a drain on your memory.");
|
||||
player.autocastId = -1;
|
||||
player.getPlayerAssistant().resetAutocast();
|
||||
}
|
||||
break;
|
||||
case "item":
|
||||
try {
|
||||
if (arguments.length == 0) {
|
||||
player.getPacketSender().sendMessage("Must specify an item id: ::item 995 1000");
|
||||
return;
|
||||
}
|
||||
int newItemID = Integer.parseInt(arguments[0]);
|
||||
int newItemAmount = arguments.length >= 2 ? Integer.parseInt(arguments[1]) : 1;
|
||||
if (newItemID <= 10000 && newItemID >= 0) {
|
||||
player.getItemAssistant().addItem(newItemID, newItemAmount);
|
||||
if (player.isBusy()) {
|
||||
player.getPacketSender().closeAllWindows();
|
||||
}
|
||||
// player.getPacketSender().sendMessage("You spawn " + newItemAmount + " × "+ ItemAssistant.getItemName(newItemID) + ".");
|
||||
} else {
|
||||
player.getPacketSender().sendMessage("No such item.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
break;
|
||||
case "master":
|
||||
for (int i = 0; i < 25; i++) {
|
||||
player.playerLevel[i] = 99;
|
||||
@@ -1091,27 +1041,6 @@ public class Commands implements PacketType {
|
||||
player.getPacketSender().object(Integer.parseInt(arguments[0]), player.absX, player.absY, player.heightLevel, 0, 0);
|
||||
Region.addObject(Integer.parseInt(arguments[0]), player.absX, player.absY, player.heightLevel, 0, 0, false);
|
||||
break;
|
||||
case "npc":
|
||||
try {
|
||||
if (arguments.length == 0) {
|
||||
player.getPacketSender().sendMessage("You must specify an ID: ::npc 1000");
|
||||
return;
|
||||
}
|
||||
int newNPC = Integer.parseInt(arguments[0]),
|
||||
maxHit = NpcHandler.getNpcListCombat(newNPC) / 10,
|
||||
attack = NpcHandler.getNpcListCombat(newNPC),
|
||||
defence = NpcHandler.getNpcListCombat(newNPC);
|
||||
boolean attackPlayer = NpcHandler.getNpcListCombat(newNPC) > 0;
|
||||
if (newNPC > 0) {
|
||||
NpcHandler.spawnNpc(player, newNPC, player.absX, player.absY, player.heightLevel, 0, NpcHandler.getNpcListHP(newNPC), maxHit, attack, defence, attackPlayer, false);
|
||||
player.getPacketSender().sendMessage("You spawn a " + NpcHandler.getNpcListName(newNPC) + ".");
|
||||
//player.npcSpawned = newNPC;
|
||||
} else {
|
||||
player.getPacketSender().sendMessage("Npc " + newNPC + " does not exist.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
break;
|
||||
case "cantattack":
|
||||
player.npcCanAttack = !player.npcCanAttack;
|
||||
player.getPacketSender().sendMessage("Npcs " + (player.npcCanAttack ? "can" : "can no longer") + " attack you.");
|
||||
|
||||
Reference in new issue
Block a user