aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-02-05 21:48:00 +0100
committernea <nea@nea.moe>2023-02-05 21:48:00 +0100
commit7f31ef0f37533482b508fb726b49978619e0e0b7 (patch)
treef5afc0fba780914c69fe326908716807b6102d76 /src/main/kotlin
parent0d140db0233780620d86c3af8917ee695bdf7e4c (diff)
downloadNotEnoughUpdates-7f31ef0f37533482b508fb726b49978619e0e0b7.tar.gz
NotEnoughUpdates-7f31ef0f37533482b508fb726b49978619e0e0b7.tar.bz2
NotEnoughUpdates-7f31ef0f37533482b508fb726b49978619e0e0b7.zip
wip
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt
index 0010f1a6..f11738fc 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt
@@ -21,14 +21,18 @@ package io.github.moulberry.notenoughupdates.util.brigadier
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.ParseResults
+import com.mojang.brigadier.tree.ArgumentCommandNode
+import com.mojang.brigadier.tree.CommandNode
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
import io.github.moulberry.notenoughupdates.util.LRUCache
import net.minecraft.command.ICommandSender
import net.minecraftforge.client.ClientCommandHandler
+import java.util.*
@NEUAutoSubscribe
object BrigadierRoot {
+ private val help: MutableMap<CommandNode<DefaultSource>, String> = IdentityHashMap()
var dispatcher = CommandDispatcher<DefaultSource>()
private set
val parseText =
@@ -36,6 +40,34 @@ object BrigadierRoot {
dispatcher.parse(text, sender)
}, 1)
+ fun getHelpForNode(node: CommandNode<DefaultSource>): String? {
+ return help[node]
+ }
+
+ fun setHelpForNode(node: CommandNode<DefaultSource>, helpText: String) {
+ help[node] = helpText
+ }
+
+
+ fun getAllUsages(
+ path: String,
+ node: CommandNode<ICommandSender>,
+ visited: MutableSet<CommandNode<ICommandSender>>
+ ): Sequence<NEUBrigadierHook.Usage> = sequence {
+ if (node in visited) return@sequence
+ visited.add(node)
+ yield(NEUBrigadierHook.Usage(path, getHelpForNode(node)))
+ node.children.forEach {
+ val nodeName = when(node) {
+ is ArgumentCommandNode<*, *> -> "<${node.name}>"
+ else -> node.name
+ }
+ yieldAll(getAllUsages("$path $nodeName", it, visited))
+ }
+ visited.remove(node)
+ }
+
+
fun updateHooks() = registerHooks(ClientCommandHandler.instance)
fun registerHooks(handler: ClientCommandHandler) {
@@ -45,6 +77,8 @@ object BrigadierRoot {
iterator.remove()
}
dispatcher = CommandDispatcher()
+ help.clear()
+ parseText.clearCache()
val event = RegisterBrigadierCommandEvent(this)
event.post()
event.hooks.forEach {