From 83952890dae702fa2ae50cc7c86c05a0982bbaba Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 9 Sep 2023 11:27:46 +0200 Subject: fixed tab complete when multiple sack items start with the same word --- .../misc/tabcomplete/GetFromSacksTabComplete.kt | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/GetFromSacksTabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/GetFromSacksTabComplete.kt index 6368a94b7..1fc7521d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/GetFromSacksTabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/GetFromSacksTabComplete.kt @@ -1,26 +1,44 @@ package at.hannibal2.skyhanni.features.misc.tabcomplete import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.jsonobjects.SackListJson +import net.minecraft.network.play.client.C01PacketChatMessage import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object GetFromSacksTabComplete { private val config get() = SkyHanniMod.feature.misc.tabCompleteCommands - private var sackListJson: SackListJson? = null + private var sackList = emptyList() private val commands = arrayOf("gfs", "getfromsacks") @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { - sackListJson = event.getConstant("Sacks") + sackList = event.getConstant("Sacks")?.sackList ?: return } fun handleTabComplete(command: String): List? { if (!isEnabled()) return null if (command !in commands) return null - return sackListJson?.sackList + return sackList.map { it.replace(" ", "_") } + } + + @SubscribeEvent + fun onSendPacket(event: PacketEvent.SendEvent) { + if (!isEnabled()) return + + val packet = event.packet as? C01PacketChatMessage ?: return + val message = packet.message + if (commands.any { message.startsWith("/$it ") }) { + val rawName = message.split(" ")[1] + val realName = rawName.replace("_", " ") + if (realName in sackList) { + event.isCanceled = true + LorenzUtils.sendMessageToServer(message.replace(rawName, realName)) + } + } } fun isEnabled() = LorenzUtils.inSkyBlock && config.gfsSack -- cgit