aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/event
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-01-13 10:19:49 -1000
committerGitHub <noreply@github.com>2024-01-13 21:19:49 +0100
commitff5863c2964cfe06c310725dd6b6fe0cd349e469 (patch)
tree8fbfc7f2ab7ef660d79098be0992dcd2b0605817 /src/main/java/at/hannibal2/skyhanni/features/event
parenta4622cf06a41cac6eb012c798a9184462c804285 (diff)
downloadskyhanni-ff5863c2964cfe06c310725dd6b6fe0cd349e469.tar.gz
skyhanni-ff5863c2964cfe06c310725dd6b6fe0cd349e469.tar.bz2
skyhanni-ff5863c2964cfe06c310725dd6b6fe0cd349e469.zip
fix gift detection (#875)
Fixed Unique Gifting Opportunities working with Golden Gift. #875
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/event')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportunitiesFeatures.kt38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportunitiesFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportunitiesFeatures.kt
index a3bc56396..78fbbe836 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportunitiesFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/UniqueGiftingOpportunitiesFeatures.kt
@@ -5,6 +5,8 @@ import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.WinterAPI
import at.hannibal2.skyhanni.events.EntityCustomNameUpdateEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.RenderMobColoredEvent
import at.hannibal2.skyhanni.events.withAlpha
import at.hannibal2.skyhanni.features.event.winter.UniqueGiftCounter
@@ -14,7 +16,9 @@ import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.getLorenzVec
+import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.entity.EntityPlayerSP
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
@@ -26,7 +30,17 @@ object UniqueGiftingOpportunitiesFeatures {
private val playerList: MutableSet<String>?
get() = ProfileStorageData.playerSpecific?.winter?.playersThatHaveBeenGifted
- private val pattern = "§6\\+1 Unique Gift given! To ([^§]+)§r§6!".toPattern()
+ private val patternGroup = RepoPattern.group("event.winter.uniquegifts")
+ private val giftedPattern by patternGroup.pattern(
+ "gifted",
+ "§6\\+1 Unique Gift given! To ([^§]+)§r§6!"
+ )
+ private val giftNamePattern by patternGroup.pattern(
+ "giftname",
+ "(?:WHITE|RED|GREEN)_GIFT\$"
+ )
+
+ private var holdingGift = false
private fun hasGiftedPlayer(player: EntityPlayer) = playerList?.contains(player.name) == true
@@ -36,9 +50,7 @@ object UniqueGiftingOpportunitiesFeatures {
private val config get() = SkyHanniMod.feature.event.winter.giftingOpportunities
- private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && WinterAPI.isDecember() &&
- (InventoryUtils.itemInHandId.endsWith("_GIFT")
- || !config.highlighWithGiftOnly)
+ private fun isEnabled() = holdingGift
private val hasNotGiftedNametag = "§a§lꤥ"
private val hasGiftedNametag = "§c§lꤥ"
@@ -85,9 +97,25 @@ object UniqueGiftingOpportunitiesFeatures {
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
- pattern.matchMatcher(event.message) {
+ giftedPattern.matchMatcher(event.message) {
addGiftedPlayer(group(1))
UniqueGiftCounter.addUniqueGift()
}
}
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ holdingGift = false
+
+ if (!LorenzUtils.inSkyBlock) return
+ if (!config.enabled) return
+ if (!WinterAPI.isDecember()) return
+
+ holdingGift = !config.highlighWithGiftOnly || giftNamePattern.matches(InventoryUtils.itemInHandId.asString())
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ holdingGift = false
+ }
}