Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: command list #163

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,32 @@ on_command("clip", Privilege.ADMIN_POWER) {
}
}

on_command("cmds", Privilege.ADMIN_POWER) {
val command = get_all_commands().joinToString()
val messages = ArrayList<String>()
var buf = ""
val split = command.split(", ")
split.forEach { s ->
buf += s
buf += ", "
if (buf.length > 75) {
messages.add(buf)
buf = ""
}
}
if(buf != "") {
buf = buf.substring(0, buf.length-2)
messages.add(buf)
}
player.message("Commands:")
messages.forEach { s -> player.message(s)}
}

fun tryWithUsage(player: Player, args: Array<String>, failMessage: String, tryUnit: Function1<Array<String>, Unit>) {
try {
tryUnit.invoke(args)
} catch (e: Exception) {
player.message(failMessage)
e.printStackTrace()
}
}
}
4 changes: 4 additions & 0 deletions game/src/main/kotlin/gg/rsmod/game/plugin/KotlinPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ abstract class KotlinPlugin(private val r: PluginRepository, val world: World, v
*/
fun on_item_on_npc(item: Int, npc: Int, plugin: Plugin.() -> Unit) = r.bindItemOnNpc(npc = npc, item = item, plugin = plugin)

fun get_all_commands(): ArrayList<String> {
return r.get_all_commands()
}

companion object {
private val METADATA_PATH = Paths.get("./plugins", "configs")
}
Expand Down
6 changes: 6 additions & 0 deletions game/src/main/kotlin/gg/rsmod/game/plugin/PluginRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1253,5 +1253,11 @@ class PluginRepository(val world: World) {
}
}

fun get_all_commands(): ArrayList<String> {
val str_list = ArrayList<String>()
commandPlugins.forEach { t, _ -> str_list.add(t) }
return str_list
}

companion object : KLogging()
}