aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt
blob: 16fee2d3503842e2a3c0e1b73c27231671b90e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package at.hannibal2.skyhanni.features.fishing

import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class SeaCreatureManager {

    @SubscribeEvent
    fun onRepoReload(event: RepositoryReloadEvent) {
        seaCreatureMap.clear()
        var counter = 0

        try {
            val data = event.getConstant("SeaCreatures")!!

            for (variant in data.entrySet().map { it.value.asJsonObject }) {
                val chatColor = variant["chat_color"].asString
                for ((displayName, value) in variant["sea_creatures"].asJsonObject.entrySet()) {
                    val seaCreature = value.asJsonObject
                    val chatMessage = seaCreature["chat_message"].asString
                    val fishingExperience = seaCreature["fishing_experience"].asInt

                    val rare = if (seaCreature.has("rare")) {
                         seaCreature["rare"].asBoolean
                    } else false

                    seaCreatureMap[chatMessage] = SeaCreature(displayName, fishingExperience, chatColor, rare)
                    counter++
                }
            }
            LorenzUtils.debug("Loaded $counter sea creatures from repo")

        } catch (e: Exception) {
            e.printStackTrace()
            LorenzUtils.error("error in RepositoryReloadEvent")
        }
    }

    companion object {
        private val seaCreatureMap = mutableMapOf<String, SeaCreature>()

        fun getSeaCreature(message: String): SeaCreature? {
            return seaCreatureMap.getOrDefault(message, null)
        }
    }
}