diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-09 11:27:46 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-09 11:27:46 +0200 |
commit | 83952890dae702fa2ae50cc7c86c05a0982bbaba (patch) | |
tree | 0a54bb4aff5122fb9298dd563787973459616050 /src/main/java/at | |
parent | 6099ebfc0488b94769fcbdb42fd1d50801caf299 (diff) | |
download | skyhanni-83952890dae702fa2ae50cc7c86c05a0982bbaba.tar.gz skyhanni-83952890dae702fa2ae50cc7c86c05a0982bbaba.tar.bz2 skyhanni-83952890dae702fa2ae50cc7c86c05a0982bbaba.zip |
fixed tab complete when multiple sack items start with the same word
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/GetFromSacksTabComplete.kt | 24 |
1 files changed, 21 insertions, 3 deletions
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<String>() private val commands = arrayOf("gfs", "getfromsacks") @SubscribeEvent fun onRepoReload(event: RepositoryReloadEvent) { - sackListJson = event.getConstant<SackListJson>("Sacks") + sackList = event.getConstant<SackListJson>("Sacks")?.sackList ?: return } fun handleTabComplete(command: String): List<String>? { 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 |