aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/fishing
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-19 17:13:28 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-19 17:13:28 +0200
commitdbfd0b107c2abf1966300dfc6dd7f34329fc282c (patch)
tree19ab3e018214bb932b6a65465135b95baee778bc /src/main/java/at/hannibal2/skyhanni/features/fishing
parentb45fd460c0a91de19fa7cc6e95b4987e9cdc25d5 (diff)
downloadskyhanni-dbfd0b107c2abf1966300dfc6dd7f34329fc282c.tar.gz
skyhanni-dbfd0b107c2abf1966300dfc6dd7f34329fc282c.tar.bz2
skyhanni-dbfd0b107c2abf1966300dfc6dd7f34329fc282c.zip
Show total amount of all rarities at the end of the chat message
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/fishing')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt61
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt5
2 files changed, 37 insertions, 29 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt
index e48df80e8..bdefdebf6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt
@@ -1,10 +1,13 @@
package at.hannibal2.skyhanni.features.fishing
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
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.removeColor
@@ -14,7 +17,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class TrophyFishMessages {
private var hasLoadedTrophyFish = false
- private val fishAmounts = mutableMapOf<String, Int>()
+ private val fishes get() = ProfileStorageData.profileSpecific?.crimsonIsle?.trophyFishes
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\\.")
private val config get() = SkyHanniMod.feature.fishing
@@ -27,26 +30,17 @@ class TrophyFishMessages {
@SubscribeEvent
fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) {
if (hasLoadedTrophyFish) return
+ val trophyFishes = fishes ?: return
val profileData = event.profileData
-
- fishAmounts.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
- }
+ trophyFishes.clear()
+ for ((rawName, value) in profileData["trophy_fish"].asJsonObject.entrySet()) {
+ val rarity = getByName(rawName) ?: continue
val text = rawName.replace("_", "")
- val displayName = text.substring(0, text.length - rarity.length)
+ val displayName = text.substring(0, text.length - rarity.name.length)
val amount = value.asInt
-// LorenzDebug.log("$rarity: $displayName: $amount")
- val fish = rarity + "_" + displayName
- fishAmounts[fish] = amount
-// LorenzDebug.log("loaded trophy: $fish = $amount")
+ val rarities = trophyFishes.getOrPut(displayName) { mutableMapOf() }
+ rarities[rarity] = amount
hasLoadedTrophyFish = true
}
}
@@ -59,13 +53,14 @@ class TrophyFishMessages {
val displayName = match["displayName"]!!.value.replace("§k", "")
val displayRarity = match["displayRarity"]!!.value
- val name = displayName.replace("Obfuscated", "Obfuscated Fish")
+ val fishName = displayName.replace("Obfuscated", "Obfuscated Fish")
.replace("[- ]".toRegex(), "").lowercase().removeColor()
- val rarity = displayRarity.lowercase().removeColor()
+ val rawRarity = displayRarity.lowercase().removeColor()
+ val rarity = getByName(rawRarity) ?: return
- val fish = "${rarity}_${name}"
- val amount = fishAmounts.getOrDefault(fish, 0) + 1
- fishAmounts[fish] = amount
+ val trophyFishes = fishes ?: return
+ val rarities = trophyFishes.getOrPut(fishName) { mutableMapOf() }
+ val amount = rarities.addOrPut(rarity, 1)
event.blockedReason = "trophy_fish"
if (config.trophyDesign == 0 && amount == 1) {
@@ -73,18 +68,26 @@ class TrophyFishMessages {
return
}
- if (config.trophyFishBronzeHider && rarity == "bronze" && amount != 1) return
- if (config.trophyFishSilverHider && rarity == "silver" && amount != 1) return
+ if (config.trophyFishBronzeHider && rarity == TrophyRarity.BRONZE && amount != 1) return
+ if (config.trophyFishSilverHider && rarity == TrophyRarity.SILVER && amount != 1) return
+ val totalText = if (config.trophyFishTotalAmount) {
+ val total = rarities.sumAllValues()
+ " §7(${total.addSeparators()}. total)"
+ } else ""
val trophyMessage = "§6§lTROPHY FISH! " + when (config.trophyDesign) {
- 0 -> "§7$amount. §r$displayRarity $displayName"
- 1 -> "§bYou caught a $displayName $displayRarity§b. §7(${amount.addSeparators()})"
- else -> "§bYou caught your ${amount.addSeparators()}${amount.ordinal()} $displayRarity $displayName§b."
+ 0 -> "§7$amount. §r$displayRarity $displayName$totalText"
+ 1 -> "§bYou caught a $displayName $displayRarity§b. §7(${amount.addSeparators()})$totalText"
+ else -> "§bYou caught your ${amount.addSeparators()}${amount.ordinal()} $displayRarity $displayName§b.$totalText"
}
Minecraft.getMinecraft().ingameGUI.chatGUI.printChatMessageWithOptionalDeletion(
ChatComponentText(trophyMessage),
- if (config.trophyFishDuplicateHider) fish.hashCode() else 0
+ if (config.trophyFishDuplicateHider) (fishName + rarity).hashCode() else 0
)
}
-} \ No newline at end of file
+
+ fun getByName(rawName: String) = TrophyRarity.values().firstOrNull { rawName.uppercase().endsWith(it.name) }
+
+ data class TrophyFish(val rarities: MutableMap<TrophyRarity, Int> = mutableMapOf())
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt
new file mode 100644
index 000000000..b87d3d60e
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyRarity.kt
@@ -0,0 +1,5 @@
+package at.hannibal2.skyhanni.features.fishing
+
+enum class TrophyRarity {
+ BRONZE, SILVER, GOLD, DIAMOND;
+} \ No newline at end of file