diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/nether/PabloHelper.kt | 11 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt | 9 |
2 files changed, 15 insertions, 5 deletions
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 (?<flower>[\\w ]+).*".toPattern() + private val patterns = listOf( + "\\[NPC] Pablo: Could you bring me an (?<flower>[\\w ]+).*".toPattern(), + "\\[NPC] Pablo: Bring me that (?<flower>[\\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 <T> List<Pattern>.matchMatchers(text: String, consumer: Matcher.() -> T): T? { + for (pattern in iterator()) { + pattern.matchMatcher<T>(text) { + return consumer() + } + } + return null + } + fun getColor(string: String, default: Int, darker: Boolean = true): Int { val stringPattern = "ยง[0123456789abcdef].*".toPattern() |