aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorappable <enzospiacitelli@gmail.com>2023-03-23 04:25:28 -0700
committerGitHub <noreply@github.com>2023-03-23 12:25:28 +0100
commite7c8613f2bfbf5c93479e63c5d6fca78b525cfc4 (patch)
treee740c96a60ff2ec44434a5c525aebd5cbe51831f
parent178f081be7b877aea7c1e965135fa1d9b87714d0 (diff)
downloadskyhanni-e7c8613f2bfbf5c93479e63c5d6fca78b525cfc4.tar.gz
skyhanni-e7c8613f2bfbf5c93479e63c5d6fca78b525cfc4.tar.bz2
skyhanni-e7c8613f2bfbf5c93479e63c5d6fca78b525cfc4.zip
Merge pull request #20
* regex for trophy fish + customizable formatting options * hide duplicate fish * don't load trophy fish repeatedly per profile + cleanup * rework config option for readability * i messed up the regex in two ways that somehow cancelled out, but thi… * using config instead of SkyHanniMod.feature.fishing everywhere * Added to changelog files and give credits
-rw-r--r--CHANGELOG.md2
-rw-r--r--FEATURES.md4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/TrophyFishMessages.kt73
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt21
5 files changed, 80 insertions, 37 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3268fd0b5..2b5ab7eca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@
+ Added **Unclaimed Rewards** - Highlight contests with unclaimed rewards in the jacob inventory.
+ Added **Duplicate Hider** - Hides duplicate farming contests in the inventory.
+ Added **Contest Time** - Adds the real time format to the farming contest description.
++ Added **Hide Repeated Catches** - Delete past catches of the same trophy fish from chat. - (Thanks appable0)
++ Added **Trophy Counter Design** - Change the way trophy fish messages gets displayed in the chat. - (Thanks appable0)
### Garden Features
+ Added **Copper Price** - Show copper to coin prices inside the Sky Mart inventory.
diff --git a/FEATURES.md b/FEATURES.md
index edcb42b66..eda125564 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -107,7 +107,9 @@
- Highlight Thunder Sparks that spawn after killing a Thunder.
- **Barn Timer** - Show the time and amount of sea creatures while fishing on the barn via hub.
- **Shark Fish Counter** - Counts how many sharks have been caught.
-- **Added Odger waypoint** - Show the Odger waypoint when trophy fishes are in the inventory and no lava rod in hand.
+- **Odger waypoint** - Show the Odger waypoint when trophy fishes are in the inventory and no lava rod in hand.
++ **Hide Repeated Catches** - Delete past catches of the same trophy fish from chat. - (Thanks appable0
++ **Trophy Counter Design** - Change the way trophy fish messages gets displayed in the chat. - (Thanks appable0)
## Damage Indicator
- Show the remaining health of selected bosses in the game in a bigger GUI.
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 d745db119..3d4dc3df5 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java
@@ -20,6 +20,23 @@ public class Fishing {
public boolean trophyCounter = false;
@Expose
+ @ConfigOption(
+ name = "Trophy Counter Design",
+ desc = "§fStyle 1: §72. §6§lGOLD §5Moldfin\n" +
+ "§fStyle 2: §bYou caught a §5Moldfin §6§lGOLD§b. §7(2)\n" +
+ "§fStyle 3: §bYou caught your 2nd §6§lGOLD §5Moldfin§b."
+ )
+ @ConfigEditorDropdown(values = {"Style 1", "Style 2", "Style 3"})
+ @ConfigAccordionId(id = 0)
+ public int trophyDesign = 0;
+
+ @Expose
+ @ConfigOption(name = "Hide Repeated Catches", desc = "Delete past catches of the same trophy fish from chat.")
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 0)
+ public boolean trophyFishDuplicateHider = 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 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
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 6da701b78..397613f40 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils
+import at.hannibal2.skyhanni.utils.NumberUtil.addSuffix
import java.text.NumberFormat
import java.util.*
import java.util.regex.Pattern
@@ -74,17 +75,25 @@ object NumberUtil {
return (this * scale).roundToInt().toFloat() / scale
}
- fun Number.addSuffix(): String {
+ fun Number.ordinal(): String {
val long = this.toLong()
- if (long in 11..13) return "${this}th"
+ if (long % 100 in 11..13) return "th"
return when (long % 10) {
- 1L -> "${this}st"
- 2L -> "${this}nd"
- 3L -> "${this}rd"
- else -> "${this}th"
+ 1L -> "st"
+ 2L -> "nd"
+ 3L -> "rd"
+ else -> "th"
}
}
+ fun Number.addSuffix(): String {
+ return this.toString() + this.ordinal()
+ }
+
+ fun Number.addSeparators(): String {
+ return NumberFormat.getNumberInstance().format(this)
+ }
+
fun String.romanToDecimalIfNeeded() = toIntOrNull() ?: romanToDecimal()
/**