aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/fishing
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-10-21 22:56:53 +1100
committerGitHub <noreply@github.com>2023-10-21 13:56:53 +0200
commit526365859a27d54b7ea5c07c08b301650c15ea0e (patch)
treeddf772f564d85caf3dbe73c66c032affdf69281f /src/main/java/at/hannibal2/skyhanni/features/fishing
parenta98927303854058ad2d7a0d8bb88265c54139614 (diff)
downloadskyhanni-526365859a27d54b7ea5c07c08b301650c15ea0e.tar.gz
skyhanni-526365859a27d54b7ea5c07c08b301650c15ea0e.tar.bz2
skyhanni-526365859a27d54b7ea5c07c08b301650c15ea0e.zip
Backend: Serialise all constants and add repo error messages and status (#605)
Backend: Serialise all constants and add repo error messages and status #605
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/fishing')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishInfo.kt54
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt57
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt15
4 files changed, 58 insertions, 73 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt
index 0ae437db7..2775becc7 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishFillet.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.fishing.trophy
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
+import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.getFilletValue
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -13,7 +14,6 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.input.Keyboard
class TrophyFishFillet {
-
@SubscribeEvent
fun onTooltip(event: LorenzToolTipEvent) {
if (!isEnabled()) return
@@ -36,5 +36,4 @@ class TrophyFishFillet {
}
private fun isEnabled() = LorenzUtils.inSkyBlock && SkyHanniMod.feature.fishing.trophyFishing.filletTooltip
-
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishInfo.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishInfo.kt
deleted file mode 100644
index aba9f5c5f..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishInfo.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-package at.hannibal2.skyhanni.features.fishing.trophy
-
-import at.hannibal2.skyhanni.test.command.ErrorManager
-import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
-import at.hannibal2.skyhanni.utils.StringUtils.splitLines
-import com.google.gson.annotations.Expose
-import net.minecraft.event.HoverEvent
-import net.minecraft.util.ChatComponentText
-import net.minecraft.util.ChatStyle
-
-data class TrophyFishInfo(
- @Expose
- val displayName: String,
- @Expose
- private val description: String,
- @Expose
- private val rate: Int?,
- @Expose
- private val fillet: Map<TrophyRarity, Int>
-) {
-
- // Credit to NotEnoughUpdates (Trophy Fish profile viewer page) for the format.
- fun getTooltip(counts: Map<TrophyRarity, Int>): ChatStyle {
- val bestFishObtained = counts.keys.maxOrNull() ?: TrophyRarity.BRONZE
- val rateString = if (rate != null) "§8[§7$rate%§8]" else ""
- val display = """
- |$displayName $rateString
- |${description.splitLines(150)}
- |
- |${TrophyRarity.DIAMOND.formattedString}: ${formatCount(counts, TrophyRarity.DIAMOND)}
- |${TrophyRarity.GOLD.formattedString}: ${formatCount(counts, TrophyRarity.GOLD)}
- |${TrophyRarity.SILVER.formattedString}: ${formatCount(counts, TrophyRarity.SILVER)}
- |${TrophyRarity.BRONZE.formattedString}: ${formatCount(counts, TrophyRarity.BRONZE)}
- |
- |§7Total: ${bestFishObtained.formatCode}${counts.values.sum().addSeparators()}
- """.trimMargin()
- return ChatStyle().setChatHoverEvent(
- HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText(display))
- )
- }
-
- fun getFilletValue(rarity: TrophyRarity): Int {
- if (fillet == null) {
- ErrorManager.logError(Error("fillet is null for '$displayName'"), "Error trying to read trophy fish info")
- return -1
- }
- return fillet.getOrDefault(rarity, -1)
- }
-
- private fun formatCount(counts: Map<TrophyRarity, Int>, rarity: TrophyRarity): String {
- val count = counts.getOrDefault(rarity, 0)
- return if (count > 0) "§6${count.addSeparators()}" else "§c✖"
- }
-} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt
index 4d8b547a4..6617b31b2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishManager.kt
@@ -2,27 +2,62 @@ package at.hannibal2.skyhanni.features.fishing.trophy
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
-import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.test.command.ErrorManager
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.StringUtils.splitLines
import at.hannibal2.skyhanni.utils.jsonobjects.TrophyFishJson
+import at.hannibal2.skyhanni.utils.jsonobjects.TrophyFishJson.TrophyFishInfo
+import net.minecraft.event.HoverEvent
+import net.minecraft.util.ChatComponentText
+import net.minecraft.util.ChatStyle
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-class TrophyFishManager {
+object TrophyFishManager {
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- val json = event.getConstant<TrophyFishJson>("TrophyFish")
- trophyFishInfo = json.trophy_fish
- LorenzUtils.debug("Loaded trophy fish from repo")
+ val data = event.getConstant<TrophyFishJson>("TrophyFish")
+ trophyFishInfo = data.trophy_fish
}
- companion object {
- val fishes: MutableMap<String, MutableMap<TrophyRarity, Int>>?
- get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes
+ val fishes: MutableMap<String, MutableMap<TrophyRarity, Int>>?
+ get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes
- private var trophyFishInfo = mapOf<String, TrophyFishInfo>()
+ private var trophyFishInfo = mapOf<String, TrophyFishInfo>()
- fun getInfo(internalName: String) = trophyFishInfo[internalName]
+ fun getInfo(internalName: String) = trophyFishInfo[internalName]
- fun getInfoByName(name: String) = trophyFishInfo.values.find { it.displayName == name }
+ fun getInfoByName(name: String) = trophyFishInfo.values.find { it.displayName == name }
+
+ private fun formatCount(counts: Map<TrophyRarity, Int>, rarity: TrophyRarity): String {
+ val count = counts.getOrDefault(rarity, 0)
+ return if (count > 0) "§6${count.addSeparators()}" else "§c✖"
+ }
+
+ fun TrophyFishInfo.getFilletValue(rarity: TrophyRarity): Int {
+ if (fillet == null) {
+ ErrorManager.logError(Error("fillet is null for '$displayName'"), "Error trying to read trophy fish info")
+ return -1
+ }
+ return fillet.getOrDefault(rarity, -1)
+ }
+
+ fun TrophyFishInfo.getTooltip(counts: Map<TrophyRarity, Int>): ChatStyle {
+ val bestFishObtained = counts.keys.maxOrNull() ?: TrophyRarity.BRONZE
+ val rateString = if (rate != null) "§8[§7$rate%§8]" else ""
+ val display = """
+ |$displayName $rateString
+ |${description.splitLines(150)}
+ |
+ |${TrophyRarity.DIAMOND.formattedString}: ${formatCount(counts, TrophyRarity.DIAMOND)}
+ |${TrophyRarity.GOLD.formattedString}: ${formatCount(counts, TrophyRarity.GOLD)}
+ |${TrophyRarity.SILVER.formattedString}: ${formatCount(counts, TrophyRarity.SILVER)}
+ |${TrophyRarity.BRONZE.formattedString}: ${formatCount(counts, TrophyRarity.BRONZE)}
+ |
+ |§7Total: ${bestFishObtained.formatCode}${counts.values.sum().addSeparators()}
+ """.trimMargin()
+ return ChatStyle().setChatHoverEvent(
+ HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText(display))
+ )
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt
index e6087a5b5..7723617a9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/trophy/TrophyFishMessages.kt
@@ -3,12 +3,14 @@ package at.hannibal2.skyhanni.features.fishing.trophy
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.events.LorenzChatEvent
-import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.Companion.fishes
+import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.fishes
+import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishManager.getTooltip
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addOrPut
import at.hannibal2.skyhanni.utils.LorenzUtils.sumAllValues
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.ordinal
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.client.Minecraft
import net.minecraft.util.ChatComponentText
@@ -16,16 +18,19 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class TrophyFishMessages {
private val trophyFishPattern =
- Regex("§6§lTROPHY FISH! §r§bYou caught an? §r(?<displayName>§[0-9a-f](?:§k)?[\\w -]+)§r§r§r §r§l§r(?<displayRarity>§[0-9a-f]§l\\w+)§r§b\\.")
+ "§6§lTROPHY FISH! §r§bYou caught an? §r(?<displayName>§[0-9a-f](?:§k)?[\\w -]+)§r§r§r §r§l§r(?<displayRarity>§[0-9a-f]§l\\w+)§r§b\\.".toPattern()
private val config get() = SkyHanniMod.feature.fishing.trophyFishing.chatMessages
@SubscribeEvent
fun onStatusBar(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock) return
+ var displayName = ""
+ var displayRarity = ""
- val match = trophyFishPattern.matchEntire(event.message)?.groups ?: return
- val displayName = match["displayName"]!!.value.replace("§k", "")
- val displayRarity = match["displayRarity"]!!.value
+ trophyFishPattern.matchMatcher(event.message) {
+ displayName = group("displayName").replace("§k", "")
+ displayRarity = group("displayRarity")
+ } ?: return
val internalName = displayName.replace("Obfuscated", "Obfuscated Fish")
.replace("[- ]".toRegex(), "").lowercase().removeColor()