aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java6
-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
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt25
6 files changed, 75 insertions, 42 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index b55e410fe..21979ffef 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.config;
import at.hannibal2.skyhanni.data.model.ComposterUpgrade;
+import at.hannibal2.skyhanni.features.fishing.TrophyRarity;
import at.hannibal2.skyhanni.features.garden.CropAccessory;
import at.hannibal2.skyhanni.features.garden.CropType;
import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems;
@@ -71,6 +72,9 @@ public class Storage {
@Expose
public List<String> kuudraTiersDone = new ArrayList<>();
+
+ @Expose
+ public Map<String, Map<TrophyRarity, Integer>> trophyFishes = new HashMap<>();
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
index f9e3fe207..e7fcff1ff 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
@@ -38,6 +38,12 @@ public class Fishing {
public boolean trophyFishDuplicateHider = false;
@Expose
+ @ConfigOption(name = "Show total amount", desc = "Show total amount of all rarities at the end of the chat message.")
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 0)
+ public boolean trophyFishTotalAmount = false;
+
+ @Expose
@ConfigOption(name = "Bronze Duplicates", desc = "Hide duplicate messages for bronze trophy fishes from chat.")
@ConfigEditorBoolean
@ConfigAccordionId(id = 0)
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
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt
index 23d58b9eb..c5a9797d6 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/SackDisplay.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi
+import at.hannibal2.skyhanni.features.fishing.TrophyRarity
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
@@ -29,7 +30,7 @@ class SackDisplay {
var isRuneSack = false
var isGemstoneSack = false
var isTrophySack = false
- var sackRarity = TrophyRarity.NONE
+ var sackRarity: TrophyRarity? = null
}
private val config get() = SkyHanniMod.feature.inventory.sackDisplay
@@ -346,19 +347,15 @@ class SackDisplay {
OBFUSCATED_2(40, 60),
OBFUSCATED_3(400, 700);
- fun convert(rarity: TrophyRarity, stored: String): String {
+ fun convert(rarity: TrophyRarity?, stored: String): String {
return when (rarity) {
TrophyRarity.BRONZE -> (this.bronzeValue * stored.formatNumber().toInt()).toString()
TrophyRarity.SILVER -> (this.silverValue * stored.formatNumber().toInt()).toString()
- TrophyRarity.NONE -> "0"
+ else -> "0"
}
}
}
- enum class TrophyRarity {
- BRONZE, SILVER, NONE
- }
-
private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled
private fun isRuneDisplayEnabled() = config.showRunes
@@ -395,13 +392,12 @@ class SackDisplay {
;
}
- private fun String.getTrophyRarity(): TrophyRarity {
+ private fun String.getTrophyRarity(): TrophyRarity? {
return if (this.startsWith("Bronze"))
TrophyRarity.BRONZE
else
if (this.startsWith("Silver"))
TrophyRarity.SILVER
- else
- TrophyRarity.NONE
+ else null
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 2c355b402..e58d05fab 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -371,11 +371,30 @@ object LorenzUtils {
fun IslandType.isInIsland() = inIsland(this)
- fun <K, N : Number> MutableMap<K, N>.addOrPut(item: K, amount: N) {
+ fun <K, N : Number> MutableMap<K, N>.addOrPut(item: K, amount: N): N {
val old = this[item] ?: 0
- val d = old.toDouble() + amount.toDouble()
+ val new = when (old) {
+ is Double -> old + amount.toDouble()
+ is Float -> old + amount.toFloat()
+ is Long -> old + amount.toLong()
+ else -> old.toInt() + amount.toInt()
+ }
@Suppress("UNCHECKED_CAST")
- this[item] = d as N
+ this[item] = new as N
+ return new
+ }
+
+ @Suppress("UNCHECKED_CAST")
+ fun <K, N : Number> MutableMap<K, N>.sumAllValues(): Double {
+ if (values.isEmpty()) {
+ return 0.0
+ }
+ return when (values.first()) {
+ is Double -> values.sumOf { it.toDouble() }
+ is Float -> values.sumOf { it.toDouble() }
+ is Long -> values.sumOf { it.toLong() }.toDouble()
+ else -> values.sumOf { it.toInt() }.toDouble()
+ }
}
/** transfer string colors from the config to java.awt.Color */