diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/BitsAPI.kt | 63 |
1 files changed, 59 insertions, 4 deletions
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() } |