aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-09-27 01:07:17 +0200
committernea <nea@nea.moe>2023-09-27 01:07:17 +0200
commit6754ab61dc56bf85dcae9a66a0040c0df6e3b2d6 (patch)
treedfd1698077c7384810c5aaedf1d645c27daf4d34 /src/main/kotlin/moe/nea
parenteaf91279b8f65b30f05a7be9a8ae1b6b18859ae4 (diff)
downloadfirmament-6754ab61dc56bf85dcae9a66a0040c0df6e3b2d6.tar.gz
firmament-6754ab61dc56bf85dcae9a66a0040c0df6e3b2d6.tar.bz2
firmament-6754ab61dc56bf85dcae9a66a0040c0df6e3b2d6.zip
Add quick /join command for catacombs and kuudra
Diffstat (limited to 'src/main/kotlin/moe/nea')
-rw-r--r--src/main/kotlin/moe/nea/firmament/Firmament.kt41
-rw-r--r--src/main/kotlin/moe/nea/firmament/commands/RestArgumentType.kt19
-rw-r--r--src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt28
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/chat/QuickCommands.kt100
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/SBData.kt1
6 files changed, 174 insertions, 17 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/Firmament.kt b/src/main/kotlin/moe/nea/firmament/Firmament.kt
index 6a6007e..3681ab6 100644
--- a/src/main/kotlin/moe/nea/firmament/Firmament.kt
+++ b/src/main/kotlin/moe/nea/firmament/Firmament.kt
@@ -14,19 +14,8 @@ import io.ktor.client.plugins.compression.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.serialization.kotlinx.json.*
-import kotlinx.coroutines.*
-import kotlinx.serialization.json.Json
-import moe.nea.firmament.commands.registerFirmamentCommand
-import moe.nea.firmament.dbus.FirmamentDbusObject
-import moe.nea.firmament.events.ItemTooltipEvent
-import moe.nea.firmament.events.ScreenRenderPostEvent
-import moe.nea.firmament.events.TickEvent
-import moe.nea.firmament.events.registration.registerFirmamentChatEvents
-import moe.nea.firmament.features.FeatureManager
-import moe.nea.firmament.repo.HypixelStaticData
-import moe.nea.firmament.repo.RepoManager
-import moe.nea.firmament.util.SBData
-import moe.nea.firmament.util.data.IDataHolder
+import java.nio.file.Files
+import java.nio.file.Path
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents
@@ -36,15 +25,32 @@ import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents
import net.fabricmc.loader.api.FabricLoader
import net.fabricmc.loader.api.Version
import net.fabricmc.loader.api.metadata.ModMetadata
-import net.minecraft.command.CommandRegistryAccess
-import net.minecraft.util.Identifier
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder
import org.freedesktop.dbus.exceptions.DBusException
-import java.nio.file.Files
-import java.nio.file.Path
+import kotlinx.coroutines.CoroutineName
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Job
+import kotlinx.coroutines.SupervisorJob
+import kotlinx.coroutines.plus
+import kotlinx.coroutines.runBlocking
+import kotlinx.serialization.json.Json
import kotlin.coroutines.EmptyCoroutineContext
+import net.minecraft.command.CommandRegistryAccess
+import net.minecraft.util.Identifier
+import moe.nea.firmament.commands.registerFirmamentCommand
+import moe.nea.firmament.dbus.FirmamentDbusObject
+import moe.nea.firmament.events.CommandEvent
+import moe.nea.firmament.events.ItemTooltipEvent
+import moe.nea.firmament.events.ScreenRenderPostEvent
+import moe.nea.firmament.events.TickEvent
+import moe.nea.firmament.events.registration.registerFirmamentChatEvents
+import moe.nea.firmament.features.FeatureManager
+import moe.nea.firmament.repo.HypixelStaticData
+import moe.nea.firmament.repo.RepoManager
+import moe.nea.firmament.util.SBData
+import moe.nea.firmament.util.data.IDataHolder
object Firmament {
const val MOD_ID = "firmament"
@@ -101,6 +107,7 @@ object Firmament {
ctx: CommandRegistryAccess
) {
registerFirmamentCommand(dispatcher)
+ CommandEvent.publish(CommandEvent(dispatcher, ctx))
}
@JvmStatic
diff --git a/src/main/kotlin/moe/nea/firmament/commands/RestArgumentType.kt b/src/main/kotlin/moe/nea/firmament/commands/RestArgumentType.kt
new file mode 100644
index 0000000..74c4011
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/commands/RestArgumentType.kt
@@ -0,0 +1,19 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.commands
+
+import com.mojang.brigadier.StringReader
+import com.mojang.brigadier.arguments.ArgumentType
+
+object RestArgumentType : ArgumentType<String> {
+ override fun parse(reader: StringReader): String {
+ val remaining = reader.remaining
+ reader.cursor += remaining.length
+ return remaining
+ }
+
+}
diff --git a/src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt b/src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt
new file mode 100644
index 0000000..c291ca4
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt
@@ -0,0 +1,28 @@
+/*
+ * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.events
+
+import com.mojang.brigadier.CommandDispatcher
+import com.mojang.brigadier.tree.LiteralCommandNode
+import net.minecraft.command.CommandRegistryAccess
+import moe.nea.firmament.commands.CaseInsensitiveLiteralCommandNode
+import moe.nea.firmament.commands.DefaultSource
+import moe.nea.firmament.commands.literal
+
+data class CommandEvent(
+ val dispatcher: CommandDispatcher<DefaultSource>,
+ val ctx: CommandRegistryAccess,
+) : FirmamentEvent() {
+ companion object : FirmamentEventBus<CommandEvent>()
+
+ fun register(
+ name: String,
+ block: CaseInsensitiveLiteralCommandNode.Builder<DefaultSource>.() -> Unit
+ ): LiteralCommandNode<DefaultSource> {
+ return dispatcher.register(literal(name, block))
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
index 48d7297..72f1056 100644
--- a/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/FeatureManager.kt
@@ -10,6 +10,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
import moe.nea.firmament.Firmament
import moe.nea.firmament.features.chat.ChatLinks
+import moe.nea.firmament.features.chat.QuickCommands
import moe.nea.firmament.features.debug.DebugView
import moe.nea.firmament.features.debug.DeveloperFeatures
import moe.nea.firmament.features.debug.MinorTrolling
@@ -53,6 +54,7 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature
loadFeature(PowerUserTools)
loadFeature(ChatLinks)
loadFeature(CompatibliltyFeatures)
+ loadFeature(QuickCommands)
loadFeature(SaveCursorPosition)
loadFeature(CustomSkyBlockTextures)
loadFeature(PriceData)
diff --git a/src/main/kotlin/moe/nea/firmament/features/chat/QuickCommands.kt b/src/main/kotlin/moe/nea/firmament/features/chat/QuickCommands.kt
new file mode 100644
index 0000000..c4a9037
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/chat/QuickCommands.kt
@@ -0,0 +1,100 @@
+/*
+ * 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.context.CommandContext
+import net.minecraft.text.Text
+import moe.nea.firmament.commands.DefaultSource
+import moe.nea.firmament.commands.RestArgumentType
+import moe.nea.firmament.commands.get
+import moe.nea.firmament.commands.thenArgument
+import moe.nea.firmament.commands.thenExecute
+import moe.nea.firmament.events.CommandEvent
+import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.SBData
+
+object QuickCommands : FirmamentFeature {
+ override val identifier: String
+ get() = "quick-commands"
+
+ fun removePartialPrefix(text: String, prefix: String): String? {
+ var lf: String? = null
+ for (i in 1..prefix.length) {
+ if (text.startsWith(prefix.substring(0, i))) {
+ lf = text.substring(i)
+ }
+ }
+ return lf
+ }
+
+ val kuudraLevelNames = listOf("NORMAL", "HOT", "BURNING", "FIERY", "INFERNAL")
+ val dungeonLevelNames = listOf("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN")
+ override fun onLoad() {
+ CommandEvent.subscribe {
+ it.register("join") {
+ thenArgument("what", RestArgumentType) { what ->
+ thenExecute {
+ val what = this[what]
+ if (!SBData.isOnSkyblock) {
+ MC.sendCommand("join $what")
+ return@thenExecute
+ }
+ val joinName = getNameForFloor(what.replace(" ", "").lowercase())
+ if (joinName == null) {
+ source.sendFeedback(Text.translatable("firmament.quick-commands.join.unknown",what))
+ } else {
+ source.sendFeedback(Text.translatable("firmament.quick-commands.join.success", joinName))
+ MC.sendCommand("joininstance $joinName")
+ }
+ }
+ }
+ thenExecute {
+ source.sendFeedback(Text.translatable("firmament.quick-commands.join.explain"))
+ }
+ }
+ }
+ }
+
+ fun CommandContext<DefaultSource>.getNameForFloor(w: String): String? {
+ val kuudraLevel = removePartialPrefix(w, "kuudratier") ?: removePartialPrefix(w, "tier")
+ if (kuudraLevel != null) {
+ val l = kuudraLevel.toIntOrNull()?.let { it - 1 } ?: kuudraLevelNames.indexOfFirst {
+ it.startsWith(
+ kuudraLevel,
+ true
+ )
+ }
+ if (l !in kuudraLevelNames.indices) {
+ source.sendFeedback(Text.translatable("firmament.quick-commands.join.unknown-kuudra", kuudraLevel))
+ return null
+ }
+ return "KUUDRA_${kuudraLevelNames[l]}"
+ }
+ val masterLevel = removePartialPrefix(w, "master")
+ val normalLevel =
+ removePartialPrefix(w, "floor") ?: removePartialPrefix(w, "catacombs") ?: removePartialPrefix(w, "dungeons")
+ val dungeonLevel = masterLevel ?: normalLevel
+ if (dungeonLevel != null) {
+ val l = dungeonLevel.toIntOrNull()?.let { it - 1 } ?: dungeonLevelNames.indexOfFirst {
+ it.startsWith(
+ dungeonLevel,
+ true
+ )
+ }
+ if (masterLevel == null && (l == -1 || null != removePartialPrefix(w, "entrance"))) {
+ return "CATACOMBS_ENTRANCE"
+ }
+ if (l !in dungeonLevelNames.indices) {
+ source.sendFeedback(Text.translatable("firmament.quick-commands.join.unknown-catacombs", kuudraLevel))
+ return null
+ }
+ return "${if (masterLevel != null) "MASTER_" else ""}CATACOMBS_FLOOR_${dungeonLevelNames[l]}"
+ }
+ return null
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/util/SBData.kt b/src/main/kotlin/moe/nea/firmament/util/SBData.kt
index 348f048..89c3a08 100644
--- a/src/main/kotlin/moe/nea/firmament/util/SBData.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/SBData.kt
@@ -30,6 +30,7 @@ object SBData {
var locraw: Locraw? = null
val skyblockLocation: String? get() = locraw?.skyblockLocation
val hasValidLocraw get() = locraw?.server !in listOf("limbo", null)
+ val isOnSkyblock get() = locraw?.gametype == "SKYBLOCK"
fun init() {
OutgoingPacketEvent.subscribe { event ->