diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
4 files changed, 72 insertions, 38 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index 967e9b02d..68761ef3a 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -80,6 +80,9 @@ public class ProfileSpecificStorage { @Expose public int bitsToClaim = -1; + + @Expose + public Long boosterCookieExpiryTime = null; } @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt index 72210ad63..a13ee259b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt @@ -8,16 +8,21 @@ import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeResets import at.hannibal2.skyhanni.utils.StringUtils.trimWhiteSpace +import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.days object BitsAPI { private val profileStorage get() = ProfileStorageData.profileSpecific?.bits @@ -41,6 +46,12 @@ object BitsAPI { profileStorage?.bitsToClaim = value } + var cookieBuffTime: SimpleTimeMark? + get() = profileStorage?.boosterCookieExpiryTime?.asTimeMark() + private set(value) { + profileStorage?.boosterCookieExpiryTime = value?.toMillis() + } + private const val defaultcookiebits = 4800 private val bitsDataGroup = RepoPattern.group("data.bits") @@ -77,6 +88,24 @@ object BitsAPI { "§7Your rank: §e(?<rank>.*)" ) + /** + * REGEX-TEST: §7Duration: §a140d 8h 35m 36s + */ + private val cookieDurationPattern by bitsGuiGroup.pattern( + "cookieduration", + "\\s*§7Duration: §a(?<time>.*)" + ) + + private val noCookieActiveSBMenuPattern by bitsGuiGroup.pattern( + "sbmenunocookieactive", + " §7Status: §cNot active!" + ) + + private val noCookieActiveCookieMenuPattern by bitsGuiGroup.pattern( + "cookiemenucookieactive", + "(§7§cYou do not currently have a|§cBooster Cookie active!)" + ) + private val fameRankCommunityShopPattern by bitsGuiGroup.pattern( "communityshopfamerank", "§7Fame Rank: §e(?<rank>.*)" @@ -115,14 +144,14 @@ object BitsAPI { bitsScoreboardPattern.matchMatcher(message) { val amount = group("amount").formatInt() + if (amount == bits) return if (amount > bits) { bitsToClaim -= amount - bits ChatUtils.debug("You have gained §3${amount - bits} Bits §7according to the scoreboard!") - sendEvent() } - - return + bits = amount + sendEvent() } } } @@ -142,6 +171,8 @@ object BitsAPI { boosterCookieAte.matchMatcher(message) { bitsToClaim += (defaultcookiebits * (currentFameRank?.bitsMultiplier ?: return)).toInt() + val cookieTime = cookieBuffTime + cookieBuffTime = if (cookieTime == null) SimpleTimeMark.now() + 4.days else cookieTime + 4.days sendEvent() return @@ -160,22 +191,33 @@ object BitsAPI { // If the cookie stack is null, then the player should not have any bits to claim if (cookieStack == null) { bitsToClaim = 0 + cookieBuffTime = SimpleTimeMark.farPast() return } - cookieStack.getLore().matchFirst(bitsAvailableMenuPattern) { + val lore = cookieStack.getLore() + lore.matchFirst(bitsAvailableMenuPattern) { val amount = group("toClaim").formatInt() if (bitsToClaim != amount) { bitsToClaim = amount sendEvent() } } + lore.matchFirst(cookieDurationPattern) { + val duration = TimeUtils.getDuration(group("time")) + cookieBuffTime = SimpleTimeMark.now() + duration + } + lore.matchFirst(noCookieActiveSBMenuPattern) { + val cookieTime = cookieBuffTime + if (cookieTime == null || cookieTime.isInFuture()) cookieBuffTime = SimpleTimeMark.farPast() + } return } if (fameRankGuiNamePattern.matches(event.inventoryName)) { val bitsStack = stacks.values.lastOrNull { bitsStackPattern.matches(it.displayName) } ?: return val fameRankStack = stacks.values.lastOrNull { fameRankGuiStackPattern.matches(it.displayName) } ?: return + val cookieStack = stacks.values.lastOrNull { cookieGuiStackPattern.matches(it.displayName) } ?: return line@ for (line in fameRankStack.getLore()) { fameRankCommunityShopPattern.matchMatcher(line) { @@ -221,9 +263,22 @@ object BitsAPI { continue@line } } + + line@ for (line in cookieStack.getLore()) { + cookieDurationPattern.matchMatcher(line) { + val duration = TimeUtils.getDuration(group("time")) + cookieBuffTime = SimpleTimeMark.now().plus(duration) + } + if (noCookieActiveCookieMenuPattern.matches(line)) { + val nextLine = cookieStack.getLore().nextAfter(line) ?: continue@line + if (noCookieActiveCookieMenuPattern.matches(nextLine)) cookieBuffTime = SimpleTimeMark.farPast() + } + } } } + fun hasCookieBuff() = cookieBuffTime?.isInFuture() ?: false + private fun sendEvent() { BitsUpdateEvent(bits, bitsToClaim).postAndCatch() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt index 65d8d880c..1b51110a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt @@ -33,7 +33,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.percentageColor import at.hannibal2.skyhanni.utils.RenderUtils.HorizontalAlignment import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.pluralize import at.hannibal2.skyhanni.utils.TabListData @@ -157,7 +156,7 @@ enum class ScoreboardElement( COOKIE( ::getCookieDisplayPair, ::getCookieShowWhen, - "§d§lCookie Buff\n §f3days, 17hours" + "§dCookie Buff§f: 3d 17h" ), EMPTY_LINE2( ::getEmptyLineDisplayPair, @@ -590,41 +589,16 @@ private fun getTuningDisplayPair(): List<Pair<String, HorizontalAlignment>> { private fun getPowerShowWhen() = !inAnyIsland(IslandType.THE_RIFT) -private fun getCookieTime(): String? { - return CustomScoreboardUtils.getTablistFooter().split("\n") - .nextAfter("§d§lCookie Buff") - ?: run { - for (line in TabListData.getTabList()) { - ScoreboardPattern.boosterCookieEffectsWidgetPattern.matchMatcher(line) { - return group("time") - } - } - null - } -} - -private fun getCookieDisplayPair(): List<ScoreboardElementType> { - val timeLine: String = getCookieTime() - ?: return listOf( - "§d§lCookie Buff" to HorizontalAlignment.LEFT, - " §7- §cNot active" to HorizontalAlignment.LEFT - ) - - return listOf( - "§d§lCookie Buff" to HorizontalAlignment.LEFT, - if (ScoreboardPattern.cookieNotActivePattern.matches(timeLine)) - " §7- §cNot active" to HorizontalAlignment.LEFT - else - " §7- §f${timeLine}" to HorizontalAlignment.LEFT - ) -} +private fun getCookieDisplayPair() = listOf( + "§dCookie Buff§f: " + (BitsAPI.cookieBuffTime?.let { + if (!BitsAPI.hasCookieBuff()) "§cNot Active" else it.timeUntil().format(maxUnits = 2) + } + ?: "§cOpen SbMenu!") to HorizontalAlignment.LEFT +) private fun getCookieShowWhen(): Boolean { if (HypixelData.bingo) return false - - return if (informationFilteringConfig.hideEmptyLines) { - getCookieTime() != null - } else true + return informationFilteringConfig.hideEmptyLines && BitsAPI.hasCookieBuff() } private fun getObjectiveDisplayPair() = buildList { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt index d6df48a67..11046a0a5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt @@ -22,6 +22,8 @@ value class SimpleTimeMark(private val millis: Long) : Comparable<SimpleTimeMark fun isInPast() = timeUntil().isNegative() + fun isInFuture() = timeUntil().isPositive() + fun isFarPast() = millis == 0L override fun compareTo(other: SimpleTimeMark): Int = millis.compareTo(other.millis) |