diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-11 11:42:54 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-11 11:42:54 +0100 |
commit | 30b959a6da9e516cfb190554584b9a013c0412f7 (patch) | |
tree | 19bace1a369130c0ff0c4466ae3755e7e79c7d58 /src/main/java/at/hannibal2 | |
parent | 5477d22a05c366095f402de10c1e0b9b15e18320 (diff) | |
download | skyhanni-30b959a6da9e516cfb190554584b9a013c0412f7.tar.gz skyhanni-30b959a6da9e516cfb190554584b9a013c0412f7.tar.bz2 skyhanni-30b959a6da9e516cfb190554584b9a013c0412f7.zip |
Pablo Helper
Diffstat (limited to 'src/main/java/at/hannibal2')
-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() |