diff options
author | nea <nea@nea.moe> | 2023-02-05 21:48:00 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-02-05 21:48:00 +0100 |
commit | 7f31ef0f37533482b508fb726b49978619e0e0b7 (patch) | |
tree | f5afc0fba780914c69fe326908716807b6102d76 /src | |
parent | 0d140db0233780620d86c3af8917ee695bdf7e4c (diff) | |
download | NotEnoughUpdates-7f31ef0f37533482b508fb726b49978619e0e0b7.tar.gz NotEnoughUpdates-7f31ef0f37533482b508fb726b49978619e0e0b7.tar.bz2 NotEnoughUpdates-7f31ef0f37533482b508fb726b49978619e0e0b7.zip |
wip
Diffstat (limited to 'src')
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 { |