aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java5
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt9
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt34
3 files changed, 43 insertions, 5 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
index aaa398f4..b20cad30 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/minionhelper/loaders/MinionHelperApiLoader.java
@@ -73,10 +73,7 @@ public class MinionHelperApiLoader {
if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) return;
if (!NotEnoughUpdates.INSTANCE.config.minionHelper.gui) return;
ticks++;
-
- if (ticks % 20 != 0) return;
-
- if (dirty) {
+ if (dirty && "Crafted Minions".equals(Utils.getOpenChestName())) {
load();
} else {
if (System.currentTimeMillis() > lastLoaded + 60_000 * 3) {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt b/src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt
index 3103d291..4b5935ce 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/brigadier/NEUBrigadierHook.kt
@@ -22,6 +22,7 @@ package io.github.moulberry.notenoughupdates.util.brigadier
import com.mojang.brigadier.ParseResults
import com.mojang.brigadier.exceptions.CommandSyntaxException
import com.mojang.brigadier.suggestion.Suggestions
+import com.mojang.brigadier.tree.ArgumentCommandNode
import com.mojang.brigadier.tree.CommandNode
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
@@ -52,8 +53,14 @@ class NEUBrigadierHook(
return aliases
}
+ data class Usage(
+ val path: String,
+ val help: String?,
+ )
+
+
override fun getCommandUsage(sender: ICommandSender): String {
- return brigadierRoot.dispatcher.getAllUsage(commandNode, sender, true).joinToString("\n")
+ return brigadierRoot.getAllUsages("/$commandName", commandNode, mutableSetOf()).joinToString("\n") { "${it.path} - ${it.help ?: "Missing help"}"}
}
private fun getText(args: Array<out String>) = "${commandNode.name} ${args.joinToString(" ")}"
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 {