From 96c657cbb5e1c9282911bb8b7b6f6239392ae07f Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:40:02 +0100 Subject: Added GetFromSackAPI. #968 --- .../tabcomplete/GetFromSacksTabComplete.kt | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/commands') diff --git a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt index 1cbc853b2..a777c76b4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/commands/tabcomplete/GetFromSacksTabComplete.kt @@ -1,44 +1,38 @@ package at.hannibal2.skyhanni.features.commands.tabcomplete import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.jsonobjects.repo.SacksJson +import at.hannibal2.skyhanni.api.GetFromSackAPI +import at.hannibal2.skyhanni.api.GetFromSackAPI.commands import at.hannibal2.skyhanni.events.MessageSendToServerEvent -import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ChatUtils.isCommand import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object GetFromSacksTabComplete { private val config get() = SkyHanniMod.feature.commands.tabComplete - private var sackList = emptyList() - private val commands = arrayOf("gfs", "getfromsacks") - - @SubscribeEvent - fun onRepoReload(event: RepositoryReloadEvent) { - sackList = event.getConstant("Sacks").sackList - } fun handleTabComplete(command: String): List? { if (!isEnabled()) return null if (command !in commands) return null - return sackList.map { it.replace(" ", "_") } + return GetFromSackAPI.sackList.map { it.asString() } } @SubscribeEvent fun onMessageSendToServer(event: MessageSendToServerEvent) { if (!isEnabled()) return - val message = event.message - if (!commands.any { message.startsWith("/$it ") }) return + if (!event.isCommand(GetFromSackAPI.commandsWithSlash)) return - val rawName = message.split(" ")[1] - val realName = rawName.replace("_", " ") - if (realName == rawName) return - if (realName !in sackList) return + val rawName = event.splitMessage[1] + val realName = rawName.asInternalName() + if (realName.asString() == rawName) return + if (realName !in GetFromSackAPI.sackList) return event.isCanceled = true - ChatUtils.sendMessageToServer(message.replace(rawName, realName)) + ChatUtils.sendMessageToServer(event.message.replace(rawName, realName.asString())) } fun isEnabled() = LorenzUtils.inSkyBlock && config.gfsSack -- cgit