diff options
| author | Lorenz <lo.scherf@gmail.com> | 2022-08-17 03:05:34 +0200 |
|---|---|---|
| committer | Lorenz <lo.scherf@gmail.com> | 2022-08-17 03:05:34 +0200 |
| commit | ef58a94bf31868c4b53218474f0be04c1cd93d97 (patch) | |
| tree | cb56d5969f8bebf586298475a61c521229663fda /src/main/java/at/hannibal2/skyhanni/features/fishing | |
| parent | 5669dbf6f68e7cacb2df6a4e37d703df8635353e (diff) | |
| download | skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.tar.gz skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.tar.bz2 skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.zip | |
moving packets around
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/fishing')
4 files changed, 177 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreature.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreature.kt new file mode 100644 index 000000000..c2b452cbe --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreature.kt @@ -0,0 +1,18 @@ +package at.hannibal2.skyhanni.features.fishing + +data class SeaCreature( + val displayName: String, + val fishingExperience: Int, + val chatColor: String, + val rare: Boolean, +) { + + override fun toString(): String { + return chatColor + rare() + displayName + } + + private fun rare(): String { + return if (rare) "§l" else "" + } +} + diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt new file mode 100644 index 000000000..c61b8dd8a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureManager.kt @@ -0,0 +1,64 @@ +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") + +// seaCreatures.asJsonArray.map { it.asJsonObject }.forEach { +// val displayName = it["display_name"].asString +// val chatMessage = it["chat_message"].asString +// val fishingExperience = it["fishing_experience"].asInt +// val variantName = it["variant"].asString +// val special = it["special"].asBoolean +// +// val variant = try { +// FishingVariant.fromString(variantName) +// } catch (e: FishingVariantNotFoundException) { +// LorenzUtils.error("Error loading Sea Creature '$displayName': " + e.message) +// return +// } +// +// seaCreatureMap[chatMessage] = SeaCreature(displayName, fishingExperience, variant, special) +// } + + } catch (e: Exception) { + e.printStackTrace() + LorenzUtils.error("error in RepositoryReloadEvent") + } + } + + companion object { + val seaCreatureMap = mutableMapOf<String, SeaCreature>() + + fun getSeaCreature(message: String): SeaCreature? { + return seaCreatureMap.getOrDefault(message, null) + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt new file mode 100644 index 000000000..21703d227 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/SeaCreatureMessageShortener.kt @@ -0,0 +1,24 @@ +package at.hannibal2.skyhanni.features.fishing + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class SeaCreatureMessageShortener { + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.fishing.shortenFishingMessage) return + + val seaCreature = SeaCreatureManager.getSeaCreature(event.message) + if (seaCreature != null) { + event.blockedReason = "sea_create_caught" + LorenzUtils.chat("§9You caught a $seaCreature§9!") + if (seaCreature.fishingExperience == 0) { + LorenzUtils.debug("no fishing exp set for " + seaCreature.displayName) + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt new file mode 100644 index 000000000..a87433762 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt @@ -0,0 +1,71 @@ +package at.hannibal2.skyhanni.features.fishing + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.between +import at.hannibal2.skyhanni.utils.LorenzUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class TrophyFishMessages { + + private val map = mutableMapOf<String, Int>() + + @SubscribeEvent + fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { + val profileData = event.profileData + + map.clear() + val trophyFishes = profileData["trophy_fish"].asJsonObject + for ((rawName, value) in trophyFishes.entrySet()) { + val rarity = when { + rawName.endsWith("_bronze") -> "bronze" + rawName.endsWith("_silver") -> "silver" + rawName.endsWith("_gold") -> "gold" + rawName.endsWith("_diamond") -> "diamond" + else -> continue + } + val text = rawName.replace("_", "") + val displayName = text.substring(0, text.length - rarity.length) + + val amount = value.asInt + +// LorenzDebug.log("$rarity: $displayName: $amount") + val name = rarity + "_" + displayName + map[name] = amount +// LorenzDebug.log("loaded trophy: $name = $amount") + } + } + + @SubscribeEvent + fun onStatusBar(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.fishing.trophyCounter) return + + val message = event.message + if (message.startsWith("§6§lTROPHY FISH! §r§bYou caught a")) { + var displayName = if (message.contains(" a §r")) message.between(" a §r", "§r §r") else message.between(" an §r", "§r §r") + if (displayName.contains("§k")) { + displayName = displayName.replace("§k", "") + displayName = displayName.replace("Obfuscated", "Obfuscated Fish") + } + val rarity = message.between("§r §r", "§b.").lowercase().replace("§l", "") + + val name = (rarity + "_" + displayName).removeColor().lowercase().replace(" ", "") + val amount = map.getOrDefault(name, 0) + 1 + map[name] = amount + event.blockedReason = "trophy_fish" + + if (amount == 1) { + LorenzUtils.chat("§6TROPHY FISH! §c§lFIRST §r$rarity $displayName") + } else { + if (rarity.contains("bronze")) { + if (SkyHanniMod.feature.fishing.trophyFishBronzeHider) return + } + LorenzUtils.chat("§6TROPHY FISH! §7$amount. §r$rarity $displayName") + } +// LorenzDebug.log("new trophy: $name = $amount") + } + } +}
\ No newline at end of file |
