Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tech.thatgravyboat.skyblockapi.api.data

import tech.thatgravyboat.skyblockapi.api.remote.api.SkyBlockId
import tech.thatgravyboat.skyblockapi.utils.extentions.toFormattedName
import tech.thatgravyboat.skyblockapi.utils.text.Text
import tech.thatgravyboat.skyblockapi.utils.text.TextColor
import tech.thatgravyboat.skyblockapi.utils.text.TextStyle.color

enum class CrystalType(val textColor: Int, skyblockId: String? = null) {
JADE(TextColor.GREEN),
AMBER(TextColor.GOLD),
AMETHYST(TextColor.DARK_PURPLE),
SAPPHIRE(TextColor.AQUA),
TOPAZ(TextColor.YELLOW),
JASPER(TextColor.LIGHT_PURPLE),
RUBY(TextColor.RED),
OPAL(TextColor.WHITE),
AQUAMARINE(TextColor.DARK_BLUE),
PERIDOT(TextColor.DARK_GREEN),
ONYX(TextColor.DARK_GRAY),
CITRINE(TextColor.DARK_RED),
;

val id = SkyBlockId.item(skyblockId ?: "${name.lowercase()}_crystal")

val displayName = Text.of("${toFormattedName()} Crystal") {
this.color = textColor
}
}

enum class CrystalStatus {
NOT_FOUND,
FOUND,
PLACED,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package tech.thatgravyboat.skyblockapi.api.data.stored

import me.owdding.ktmodules.Module
import tech.thatgravyboat.skyblockapi.api.data.CrystalStatus
import tech.thatgravyboat.skyblockapi.api.data.CrystalType
import tech.thatgravyboat.skyblockapi.api.data.StoredProfileData
import tech.thatgravyboat.skyblockapi.api.events.base.Subscription
import tech.thatgravyboat.skyblockapi.api.events.misc.RegisterCommandsEvent
import tech.thatgravyboat.skyblockapi.api.profile.hotm.CrystalData
import tech.thatgravyboat.skyblockapi.utils.text.Text
import tech.thatgravyboat.skyblockapi.utils.text.Text.sendWithPrefix

@Module
internal object CrystalStorage {
private val CRYSTAL_DATA = StoredProfileData(
::CrystalData,
CrystalData.CODEC,
"crystal_data.json",
)

val crystalData: MutableMap<CrystalType, CrystalStatus> get() = CRYSTAL_DATA.get()?.crystals ?: mutableMapOf()

fun setCrystalStatusByName(typeName: String, status: CrystalStatus): Boolean {
val type = CrystalType.entries.find { it.name.equals(typeName, true) } ?: return false
crystalData[type] = status
save()
return true
}

fun save() {
CRYSTAL_DATA.save()
}

@Subscription
fun onCommandRegister(event: RegisterCommandsEvent) {
event.register("meowmrrow") {
callback {
val statuses = crystalData.entries.joinToString(", ") { "${it.key.name}: ${it.value}" }
Text.of(statuses).sendWithPrefix()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package tech.thatgravyboat.skyblockapi.api.profile.hotm

import me.owdding.ktmodules.Module
import tech.thatgravyboat.skyblockapi.api.data.CrystalStatus
import tech.thatgravyboat.skyblockapi.api.data.stored.CrystalStorage
import tech.thatgravyboat.skyblockapi.api.events.base.Subscription
import tech.thatgravyboat.skyblockapi.api.events.base.predicates.InventoryTitle
import tech.thatgravyboat.skyblockapi.api.events.chat.ChatReceivedEvent
import tech.thatgravyboat.skyblockapi.api.events.screen.InventoryChangeEvent
import tech.thatgravyboat.skyblockapi.utils.Logger
import tech.thatgravyboat.skyblockapi.utils.extentions.cleanName
import tech.thatgravyboat.skyblockapi.utils.extentions.getRawLore

@Module
object CrystalAPI {
val itemRegex = Regex("^Crystal Hollows Crystals$")

/**
* REGEX-TEST: Jade ✖ Not Found
* REGEX-TEST: Amber ✖ Not Found
* REGEX-TEST: Ruby ✔ Found
* REGEX-TEST: Jade ✔ Placed
*/
val crystalLoreRegex = Regex("^ {2}([A-Za-z]+) (✖ Not Found|✔ Found|✔ Placed)$")

/**
* REGEX-TEST: Jade Crystal
* REGEX-TEST: Amber Crystal
*/
val crystalFoundRegex = Regex("^ {32}([A-Za-z]+) Crystal$")

/**
* REGEX-TEST: ✦ You placed the Jade Crystal!
*/
val crystalPlacedRegex = Regex("^✦ You placed the ([A-Za-z]+) Crystal!$")

@Subscription
@InventoryTitle("Heart of the Mountain")
fun onInventoryChange(event: InventoryChangeEvent) {
if (!itemRegex.matches(event.item.cleanName)) return

val lore = event.item.getRawLore()
for (line in lore) {
crystalLoreRegex.matchEntire(line)?.let { match ->
val crystalName = match.groupValues[1]
val status = match.groupValues[2]
if (CrystalStorage.setCrystalStatusByName(crystalName, when (status) {
"✖ Not Found" -> CrystalStatus.NOT_FOUND
"✔ Found" -> CrystalStatus.FOUND
"✔ Placed" -> CrystalStatus.PLACED
else -> return@let
})) {
Logger.info("Updated $crystalName to $status based on inventory.")
} else {
Logger.info("Failed to update crystal status for $crystalName with status $status")
}
}
}
}

@Subscription
fun onChatReceived(event: ChatReceivedEvent.Pre) {
val message = event.text
when {
crystalFoundRegex.matches(message) -> {
val match = crystalFoundRegex.matchEntire(message) ?: return
val crystalName = match.groupValues[1]
CrystalStorage.setCrystalStatusByName(crystalName, CrystalStatus.FOUND)
}
crystalPlacedRegex.matches(message) -> {
val match = crystalPlacedRegex.matchEntire(message) ?: return
val crystalName = match.groupValues[1]
CrystalStorage.setCrystalStatusByName(crystalName, CrystalStatus.PLACED)
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tech.thatgravyboat.skyblockapi.api.profile.hotm

import com.mojang.serialization.Codec
import me.owdding.ktcodecs.GenerateCodec
import tech.thatgravyboat.skyblockapi.api.data.CrystalStatus
import tech.thatgravyboat.skyblockapi.api.data.CrystalType
import tech.thatgravyboat.skyblockapi.generated.SkyblockAPICodecs

@GenerateCodec
data class CrystalData(
var crystals: MutableMap<CrystalType, CrystalStatus> = mutableMapOf(),
) {
companion object {
val CODEC: Codec<CrystalData> = SkyblockAPICodecs.getCodec<CrystalData>()
}
}
Loading