From 714a722e748cb082af808c3168e7e7ab0c594adb Mon Sep 17 00:00:00 2001 From: Empa <42304516+ItsEmpa@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:00:12 +0200 Subject: Improvement: More pet drop messages (#1213) --- .../skyhanni/features/chat/RareDropMessages.kt | 55 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/RareDropMessages.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/RareDropMessages.kt index 6d67b757a..297c3b098 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/RareDropMessages.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/RareDropMessages.kt @@ -4,16 +4,50 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.colorCodeToRarity -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchMatchers import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class RareDropMessages { - private val petDropPattern by RepoPattern.pattern( - "pet.petdropmessage", - "(?§6§lPET DROP!|§5§lGREAT CATCH! §r§bYou found a §r§7\\[Lvl 1]) (?:§r)?§(?.)(?[^§(.]+)(?.*)" + private val chatGroup = RepoPattern.group("pet.chatdrop") + + /** + * REGEX-TEST: §6§lPET DROP! §r§5Baby Yeti §r§b(+§r§b168% §r§b✯ Magic Find§r§b) + * REGEX-TEST: §6§lPET DROP! §r§5Slug §6(§6+1300☘) + */ + private val petDroppedPattern by chatGroup.pattern( + "pet.petdroppedmessage", + "(?(?:§.)*PET DROP! )(?:§.)*§(?.)(?[^§(.]+)(? .*)" + ) + + /** + * REGEX-TEST: §5§lGREAT CATCH! §r§bYou found a §r§7[Lvl 1] §r§aGuardian§r§b. + */ + private val petFishedPattern by chatGroup.pattern( + "pet.petfishedmessage", + "(?(?:§.)*GREAT CATCH! (?:§.)*You found a (?:§.)*\\[Lvl 1] )(?:§.)*§(?.)(?[^§(.]+)(?.*)" + ) + + /** + * REGEX-TEST: §aYou claimed a §5Tarantula Pet§a! §r§aYou can manage your Pets in the §r§fPets Menu§r§a in your §r§fSkyBlock Menu§r§a. + */ + private val petClaimedPattern by chatGroup.pattern( + "pet.petclaimedmessage", + "(?(?:§.)*You claimed a )(?:§.)*§(?.)(?[^§(.]+)(?.*)" + ) + + /** + * REGEX-TEST: §b[MVP§r§c+§r§b] Empa_§r§f §r§ehas obtained §r§a§r§7[Lvl 1] §r§6Bal§r§e! + */ + private val petObtainedPattern by chatGroup.pattern( + "pet.petobtainedmessage", + "(?.*has obtained (?:§.)*\\[Lvl 1] )(?:§.)*§(?.)(?[^§(.]+)(?.*)" + ) + + private val patterns = listOf( + petDroppedPattern, petFishedPattern, petClaimedPattern, petObtainedPattern ) private val config get() = SkyHanniMod.feature.chat.petRarityDropMessage @@ -23,15 +57,18 @@ class RareDropMessages { if (!LorenzUtils.inSkyBlock) return if (!config) return - petDropPattern.matchMatcher(event.message) { - val typeOfDrop = group("typeOfDrop") + patterns.matchMatchers(event.message) { + var start = group("start") val rarityColor = group("rarityColor") + val rarityName = colorCodeToRarity(rarityColor.first()).uppercase() val petName = group("petName") - val magicFindOrFarmingFortune = group("magicFindOrFarmingFortune") + val end = group("end") + if (start.endsWith("a ") && rarityName.matches("(?i)[aeiou].*".toRegex())) + start = start.replace(" $".toRegex(), "n ") event.chatComponent = ChatComponentText( - "$typeOfDrop §$rarityColor§l${colorCodeToRarity(rarityColor.first()).uppercase()} §$rarityColor$petName$magicFindOrFarmingFortune" + "$start§$rarityColor§l$rarityName §$rarityColor$petName$end" ) - } ?: return + } } } -- cgit