aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-10-21 17:28:00 +0200
committernea <nea@nea.moe>2023-10-21 17:28:00 +0200
commite887067b7ecfa9d8e040008cca8d26c194f8c1a5 (patch)
tree8c558ed23edabd7722bf869ce24d5561b6644e44 /src/main/kotlin/moe/nea/firmament/features
parentbc758d17e2ac5c507117f85bf76b081a05f2baca (diff)
downloadfirmament-e887067b7ecfa9d8e040008cca8d26c194f8c1a5.tar.gz
firmament-e887067b7ecfa9d8e040008cca8d26c194f8c1a5.tar.bz2
firmament-e887067b7ecfa9d8e040008cca8d26c194f8c1a5.zip
Add tab completion to /warp
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/chat/AutoCompletions.kt60
2 files changed, 62 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
index b9d343c..2683775 100644
--- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
@@ -9,6 +9,7 @@ package moe.nea.firmament.features
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import moe.nea.firmament.Firmament
+import moe.nea.firmament.features.chat.AutoCompletions
import moe.nea.firmament.features.chat.ChatLinks
import moe.nea.firmament.features.chat.QuickCommands
import moe.nea.firmament.features.debug.DebugView
@@ -48,6 +49,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
if (hasAutoloaded) return
loadFeature(MinorTrolling)
loadFeature(FairySouls)
+ loadFeature(AutoCompletions)
// TODO: loadFeature(FishingWarning)
loadFeature(SlotLocking)
loadFeature(StorageOverlay)
diff --git a/src/main/kotlin/moe/nea/firmament/features/chat/AutoCompletions.kt b/src/main/kotlin/moe/nea/firmament/features/chat/AutoCompletions.kt
new file mode 100644
index 0000000..9912321
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/chat/AutoCompletions.kt
@@ -0,0 +1,60 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.features.chat
+
+import com.mojang.brigadier.arguments.StringArgumentType.string
+import moe.nea.firmament.commands.get
+import moe.nea.firmament.commands.suggestsList
+import moe.nea.firmament.commands.thenArgument
+import moe.nea.firmament.commands.thenExecute
+import moe.nea.firmament.events.CommandEvent
+import moe.nea.firmament.events.MaskCommands
+import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.gui.config.ManagedConfig
+import moe.nea.firmament.repo.RepoManager
+import moe.nea.firmament.util.MC
+
+object AutoCompletions : FirmamentFeature {
+
+ object TConfig : ManagedConfig(identifier) {
+ val provideWarpTabCompletion by toggle("warp-complete") { true }
+ val replaceWarpIsByWarpIsland by toggle("warp-is") { true }
+ }
+
+ override val config: ManagedConfig?
+ get() = TConfig
+ override val identifier: String
+ get() = "auto-completions"
+
+ override fun onLoad() {
+ MaskCommands.subscribe {
+ if (TConfig.provideWarpTabCompletion) {
+ it.mask("warp")
+ }
+ }
+ CommandEvent.subscribe {
+ if (TConfig.provideWarpTabCompletion) {
+ it.deleteCommand("warp")
+ it.register("warp") {
+ thenArgument("to", string()) { toArg ->
+ suggestsList {
+ RepoManager.neuRepo.constants?.islands?.warps?.flatMap { listOf(it.warp) + it.aliases } ?: listOf()
+ }
+ thenExecute {
+ val warpName = get(toArg)
+ if (warpName == "is" && TConfig.replaceWarpIsByWarpIsland) {
+ MC.sendServerCommand("warp island")
+ } else {
+ MC.sendServerCommand("warp ${warpName}")
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}