blob: e48df80e880aff79bcca4a6d06fa73ae2d919db8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
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.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
@SubscribeEvent
fun onProfileJoin(event: ProfileJoinEvent) {
hasLoadedTrophyFish = false
}
@SubscribeEvent
fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) {
if (hasLoadedTrophyFish) 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
}
val text = rawName.replace("_", "")
val displayName = text.substring(0, text.length - rarity.length)
val amount = value.asInt
// LorenzDebug.log("$rarity: $displayName: $amount")
val fish = rarity + "_" + displayName
fishAmounts[fish] = amount
// LorenzDebug.log("loaded trophy: $fish = $amount")
hasLoadedTrophyFish = true
}
}
@SubscribeEvent
fun onStatusBar(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock || !config.trophyCounter) return
val match = trophyFishPattern.matchEntire(event.message)?.groups ?: return
val displayName = match["displayName"]!!.value.replace("§k", "")
val displayRarity = match["displayRarity"]!!.value
val name = displayName.replace("Obfuscated", "Obfuscated Fish")
.replace("[- ]".toRegex(), "").lowercase().removeColor()
val rarity = displayRarity.lowercase().removeColor()
val fish = "${rarity}_${name}"
val amount = fishAmounts.getOrDefault(fish, 0) + 1
fishAmounts[fish] = amount
event.blockedReason = "trophy_fish"
if (config.trophyDesign == 0 && amount == 1) {
LorenzUtils.chat("§6§lTROPHY FISH! §c§lFIRST §r$displayRarity $displayName")
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."
}
Minecraft.getMinecraft().ingameGUI.chatGUI.printChatMessageWithOptionalDeletion(
ChatComponentText(trophyMessage),
if (config.trophyFishDuplicateHider) fish.hashCode() else 0
)
}
}
|