diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-18 16:21:50 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-18 17:31:39 +0100 |
commit | b6ef3d00916a836eaca6882add39781283e1f9d7 (patch) | |
tree | 8ecc927e6de7fc717bb6a8c581314ef0c3926f0a | |
parent | 68948baff37e139a2a3f88ce3b233effb55955c4 (diff) | |
download | Firmament-b6ef3d00916a836eaca6882add39781283e1f9d7.tar.gz Firmament-b6ef3d00916a836eaca6882add39781283e1f9d7.tar.bz2 Firmament-b6ef3d00916a836eaca6882add39781283e1f9d7.zip |
feat: Allow opening config with just /firm
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/RedirectWithoutSubCommands.java | 42 | ||||
-rw-r--r-- | src/main/kotlin/commands/rome.kt | 19 |
2 files changed, 49 insertions, 12 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/RedirectWithoutSubCommands.java b/src/main/java/moe/nea/firmament/mixins/RedirectWithoutSubCommands.java new file mode 100644 index 0000000..2186aee --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/RedirectWithoutSubCommands.java @@ -0,0 +1,42 @@ +package moe.nea.firmament.mixins; + +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.ParseResults; +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.context.CommandContextBuilder; +import com.mojang.brigadier.tree.CommandNode; +import moe.nea.firmament.util.ErrorUtil; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.HashSet; + +@Mixin(CommandDispatcher.class) +public class RedirectWithoutSubCommands<S> { + @Inject( + method = "parseNodes", + at = @At( + value = "INVOKE", + target = "Lcom/mojang/brigadier/context/CommandContextBuilder;withCommand(Lcom/mojang/brigadier/Command;)Lcom/mojang/brigadier/context/CommandContextBuilder;", + shift = At.Shift.AFTER + ) + ) + private void injectCommandForRedirects( + CommandNode<S> node, StringReader originalReader, CommandContextBuilder<S> contextSoFar, CallbackInfoReturnable<ParseResults<S>> cir, + @Local(index = 10) CommandContextBuilder<S> context, + @Local(index = 9) CommandNode<S> child + ) { + var p = child; + var set = new HashSet<>(); + if (context.getCommand() == null && p.getRedirect() != null) { + p = p.getRedirect(); + context.withCommand(p.getCommand()); + if (!set.add(p)) { + ErrorUtil.INSTANCE.softError("Redirect circle detected in " + p); + } + } + } +} diff --git a/src/main/kotlin/commands/rome.kt b/src/main/kotlin/commands/rome.kt index a690e1f..13acb3c 100644 --- a/src/main/kotlin/commands/rome.kt +++ b/src/main/kotlin/commands/rome.kt @@ -3,14 +3,7 @@ package moe.nea.firmament.commands import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.arguments.StringArgumentType.string import io.ktor.client.statement.bodyAsText -import java.nio.file.Path import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource -import kotlin.io.path.exists -import kotlin.io.path.fileSize -import kotlin.io.path.isDirectory -import kotlin.io.path.isReadable -import kotlin.io.path.isRegularFile -import kotlin.io.path.listDirectoryEntries import net.minecraft.nbt.NbtOps import net.minecraft.text.Text import net.minecraft.text.TextCodecs @@ -41,11 +34,7 @@ import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.accessors.messages import moe.nea.firmament.util.collections.InstanceList import moe.nea.firmament.util.collections.WeakCache -import moe.nea.firmament.util.darkGreen -import moe.nea.firmament.util.lime import moe.nea.firmament.util.mc.SNbtFormatter -import moe.nea.firmament.util.purple -import moe.nea.firmament.util.red import moe.nea.firmament.util.tr import moe.nea.firmament.util.unformattedString @@ -323,7 +312,10 @@ fun firmamentCommand() = literal("firmament") { source.sendFeedback(tr("firmament.repo.info.location", "Saved location: ${debugPath(RepoDownloadManager.repoSavedLocation)}")) source.sendFeedback(tr("firmament.repo.info.reloadstatus", - "Incomplete: ${formatBool(RepoManager.neuRepo.isIncomplete, trueIsGood = false)}, Unstable ${formatBool(RepoManager.neuRepo.isUnstable, trueIsGood = false)}")) + "Incomplete: ${ + formatBool(RepoManager.neuRepo.isIncomplete, + trueIsGood = false) + }, Unstable ${formatBool(RepoManager.neuRepo.isUnstable, trueIsGood = false)}")) source.sendFeedback(tr("firmament.repo.info.items", "Loaded items: ${RepoManager.neuRepo.items?.items?.size}")) source.sendFeedback(tr("firmament.repo.info.itemcache", @@ -333,6 +325,9 @@ fun firmamentCommand() = literal("firmament") { } } } + thenExecute { + AllConfigsGui.showAllGuis() + } CommandEvent.SubCommand.publish(CommandEvent.SubCommand(this@literal)) } |