Add quick /join command for catacombs and kuudra
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
28
src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt
Normal file
28
src/main/kotlin/moe/nea/firmament/events/CommandEvent.kt
Normal file
@@ -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))
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
100
src/main/kotlin/moe/nea/firmament/features/chat/QuickCommands.kt
Normal file
100
src/main/kotlin/moe/nea/firmament/features/chat/QuickCommands.kt
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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 ->
|
||||
|
||||
@@ -126,5 +126,10 @@
|
||||
"firmament.tooltip.copied.nbt": "Copied NBT data",
|
||||
"firmament.config.compatibility": "Intermod Features",
|
||||
"firmament.config.compatibility.explosion-enabled": "Redirect Enhanced Explosions",
|
||||
"firmament.config.compatibility.explosion-power": "Enhanced Explosion Power"
|
||||
"firmament.config.compatibility.explosion-power": "Enhanced Explosion Power",
|
||||
"firmament.quick-commands.join.unknown": "Could not find instance for %s",
|
||||
"firmament.quick-commands.join.success": "Joining: %s",
|
||||
"firmament.quick-commands.join.explain": "Join a dungeon or kuudra floor by using commands like /join f1, /join m7, /join fe or /join khot",
|
||||
"firmament.quick-commands.join.unknown-kuudra": "Unknown kuudra floor %s",
|
||||
"firmament.quick-commands.join.unknown-catacombs": "Unknown catacombs floor %s"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user