diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/fishing')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt | 73 |
1 files changed, 43 insertions, 30 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 080fa89c4..e48df80e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt @@ -3,20 +3,33 @@ 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.events.ProfileJoinEvent import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.ordinal import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.client.Minecraft +import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class TrophyFishMessages { + private var hasLoadedTrophyFish = false + private val fishAmounts = mutableMapOf<String, Int>() + 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 - private val map = mutableMapOf<String, Int>() + @SubscribeEvent + fun onProfileJoin(event: ProfileJoinEvent) { + hasLoadedTrophyFish = false + } @SubscribeEvent fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { + if (hasLoadedTrophyFish) return val profileData = event.profileData - map.clear() + fishAmounts.clear() val trophyFishes = profileData["trophy_fish"].asJsonObject for ((rawName, value) in trophyFishes.entrySet()) { val rarity = when { @@ -30,48 +43,48 @@ class TrophyFishMessages { 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") + val fish = rarity + "_" + displayName + fishAmounts[fish] = amount +// LorenzDebug.log("loaded trophy: $fish = $amount") + hasLoadedTrophyFish = true } } @SubscribeEvent fun onStatusBar(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyBlock) return - if (!SkyHanniMod.feature.fishing.trophyCounter) return + if (!LorenzUtils.inSkyBlock || !config.trophyCounter) return - val message = event.message - //TODO replace logic with regex - if (!message.startsWith("§6§lTROPHY FISH! §r§bYou caught a")) return + val match = trophyFishPattern.matchEntire(event.message)?.groups ?: return + val displayName = match["displayName"]!!.value.replace("§k", "") + val displayRarity = match["displayRarity"]!!.value - 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 = displayName.replace("Obfuscated", "Obfuscated Fish") + .replace("[- ]".toRegex(), "").lowercase().removeColor() + val rarity = displayRarity.lowercase().removeColor() - val name = (rarity + "_" + displayName).removeColor().lowercase().replace(" ", "").replace("-", "") - val amount = map.getOrDefault(name, 0) + 1 - map[name] = amount + val fish = "${rarity}_${name}" + val amount = fishAmounts.getOrDefault(fish, 0) + 1 + fishAmounts[fish] = amount event.blockedReason = "trophy_fish" - if (amount == 1) { - LorenzUtils.chat("§6TROPHY FISH! §c§lFIRST §r$rarity $displayName") + if (config.trophyDesign == 0 && amount == 1) { + LorenzUtils.chat("§6§lTROPHY FISH! §c§lFIRST §r$displayRarity $displayName") return } - if (rarity.contains("bronze")) { - if (SkyHanniMod.feature.fishing.trophyFishBronzeHider) return - } - if (rarity.contains("silver")) { - if (SkyHanniMod.feature.fishing.trophyFishSilverHider) return + if (config.trophyFishBronzeHider && rarity == "bronze" && amount != 1) return + if (config.trophyFishSilverHider && rarity == "silver" && amount != 1) return + + 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." } - LorenzUtils.chat("§6TROPHY FISH! §7$amount. §r$rarity $displayName") + Minecraft.getMinecraft().ingameGUI.chatGUI.printChatMessageWithOptionalDeletion( + ChatComponentText(trophyMessage), + if (config.trophyFishDuplicateHider) fish.hashCode() else 0 + ) } }
\ No newline at end of file |