aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/GetFromSacksTabComplete.kt24
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