From 30b959a6da9e516cfb190554584b9a013c0412f7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 11 Nov 2023 11:42:54 +0100 Subject: Pablo Helper --- .../java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt | 11 ++++++----- src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt index 89a0a1917..12b2b78df 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.SimpleTimeMark -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matchMatchers import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.minutes @@ -17,16 +17,17 @@ import kotlin.time.Duration.Companion.minutes class PabloHelper { private val config get() = SkyHanniMod.feature.crimsonIsle - // There is a different message if the player asks Pablo with an item in their hand, but I don't think it's necessary - // I'll add it if requested ~NetheriteMiner - private val pabloMessagePattern = "\\[NPC] Pablo: Could you bring me an (?[\\w ]+).*".toPattern() + private val patterns = listOf( + "\\[NPC] Pablo: Could you bring me an (?[\\w ]+).*".toPattern(), + "\\[NPC] Pablo: Bring me that (?[\\w ]+) as soon as you can!".toPattern() + ) private var lastSentMessage = SimpleTimeMark.farPast() @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return if (lastSentMessage.passedSince() < 5.minutes) return - val itemName = pabloMessagePattern.matchMatcher(event.message.removeColor()) { + val itemName = patterns.matchMatchers(event.message.removeColor()) { group("flower") } ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 0900b3812..b60c08b6f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -89,6 +89,15 @@ object StringUtils { } } + inline fun List.matchMatchers(text: String, consumer: Matcher.() -> T): T? { + for (pattern in iterator()) { + pattern.matchMatcher(text) { + return consumer() + } + } + return null + } + fun getColor(string: String, default: Int, darker: Boolean = true): Int { val stringPattern = "ยง[0123456789abcdef].*".toPattern() -- cgit