diff options
author | CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> | 2024-03-02 00:11:51 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-01 14:11:51 +0100 |
commit | 42118ca3e36d4441ed4aaffdcede5945573c43b3 (patch) | |
tree | abe1593826ea179383d8bcce12c721992d75a189 /src | |
parent | 3bfb3531113e09f49defe2c0824bd95998345673 (diff) | |
download | skyhanni-42118ca3e36d4441ed4aaffdcede5945573c43b3.tar.gz skyhanni-42118ca3e36d4441ed4aaffdcede5945573c43b3.tar.bz2 skyhanni-42118ca3e36d4441ed4aaffdcede5945573c43b3.zip |
Added stacking enchants to repo. #861
Diffstat (limited to 'src')
3 files changed, 27 insertions, 50 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/StackingEnchantsJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/StackingEnchantsJson.kt new file mode 100644 index 000000000..a663f6db8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/StackingEnchantsJson.kt @@ -0,0 +1,12 @@ +package at.hannibal2.skyhanni.data.jsonobjects.repo + +import com.google.gson.annotations.Expose + +data class StackingEnchantsJson( + @Expose val enchants: Map<String, StackingEnchantData> +) + +data class StackingEnchantData( + @Expose val levels: List<Int>, + @Expose val statName: String +) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt index bc7875822..2fb3e0241 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt @@ -8,10 +8,13 @@ import at.hannibal2.skyhanni.SkyHanniMod.Companion.feature import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.misc.DiscordRPCConfig.LineEntry import at.hannibal2.skyhanni.config.features.misc.DiscordRPCConfig.PriorityEntry +import at.hannibal2.skyhanni.data.jsonobjects.repo.StackingEnchantData +import at.hannibal2.skyhanni.data.jsonobjects.repo.StackingEnchantsJson import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ConditionalUtils @@ -49,6 +52,8 @@ object DiscordRPCManager : IPCListener { private val DiscordLocationKey = DiscordLocationKey() + var stackingEnchants: Map<String, StackingEnchantData> = emptyMap() + fun start(fromCommand: Boolean = false) { coroutineScope.launch { try { @@ -117,6 +122,11 @@ object DiscordRPCManager : IPCListener { } } + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + stackingEnchants = event.getConstant<StackingEnchantsJson>("StackingEnchants").enchants + } + fun updatePresence() { val location = DiscordStatus.LOCATION.getDisplayString() val discordIconKey = DiscordLocationKey.getDiscordIconKey(location) diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index af307e32f..de93ad491 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -40,49 +40,6 @@ val purseRegex = Regex("""(?:Purse|Piggy): ([\d,]+)[\d.]*""") val motesRegex = Regex("""Motes: ([\d,]+)""") val bitsRegex = Regex("""Bits: ([\d|,]+)[\d|.]*""") -val stackingEnchants = mapOf( - "compact" to mapOf( - "levels" to listOf(0, 100, 500, 1500, 5000, 15000, 50000, 150000, 500000, 1000000), - "nbtNum" to "compact_blocks" - ), - "cultivating" to mapOf( - "levels" to listOf( - 0, - 1000, - 5000, - 25000, - 100000, - 300000, - 1500000, - 5000000, - 20000000, - 100000000 - ), "nbtNum" to "farmed_cultivating" - ), - "expertise" to mapOf( - "levels" to listOf(0, 50, 100, 250, 500, 1000, 2500, 5500, 10000, 15000), - "nbtNum" to "expertise_kills" - ), - "hecatomb" to mapOf( - "levels" to listOf(0, 2, 5, 10, 20, 30, 40, 60, 80, 100), - "nbtNum" to "hecatomb_s_runs" - ), - "champion" to mapOf( - "levels" to listOf( - 0, - 50000, - 100000, - 250000, - 500000, - 1000000, - 1500000, - 2000000, - 2500000, - 3000000 - ), "nbtNum" to "champion_combat_xp" - ) -) // nbtNum is the id of the enchantment in the nbt data - private fun getVisitingName(): String { val tabData = getTabList() val ownerRegex = Regex(".*Owner: (\\w+).*") @@ -315,11 +272,9 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) val extraAttributes = getExtraAttributes(itemInHand) fun getProgressPercent(amount: Int, levels: List<Int>): String { - var currentLevel = 0 var percent = "MAXED" for (level in levels.indices) { if (amount > levels[level]) { - currentLevel++ continue } percent = if (amount.toDouble() == 0.0) { @@ -336,15 +291,15 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) if (extraAttributes != null) { val enchantments = extraAttributes.getCompoundTag("enchantments") var stackingEnchant = "" - for (enchant in stackingEnchants.keys) { - if (extraAttributes.hasKey(stackingEnchants[enchant]?.get("nbtNum").toString())) { - stackingEnchant = enchant + for (enchant in DiscordRPCManager.stackingEnchants) { + if (extraAttributes.hasKey(enchant.value.statName)) { + stackingEnchant = enchant.key break } } - val levels = stackingEnchants[stackingEnchant]?.get("levels") as? List<Int> ?: listOf(0) + val levels = DiscordRPCManager.stackingEnchants[stackingEnchant]?.levels ?: listOf(0) val level = enchantments.getInteger(stackingEnchant) - val amount = extraAttributes.getInteger(stackingEnchants[stackingEnchant]?.get("nbtNum").toString()) + val amount = extraAttributes.getInteger(DiscordRPCManager.stackingEnchants[stackingEnchant]?.statName) val stackingPercent = getProgressPercent(amount, levels) stackingReturn = |