-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
Copy pathPabloHelper.kt
66 lines (54 loc) · 2.7 KB
/
PabloHelper.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package at.hannibal2.skyhanni.features.nether
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.GetFromSackAPI
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveStack
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatchers
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.minutes
// https://wiki.hypixel.net/Pablo
@SkyHanniModule
object PabloHelper {
private val config get() = SkyHanniMod.feature.crimsonIsle
// TODO RepoPattern.list does not work, find out why
// /**
// * REGEX-TEST: §e[NPC] §5Pablo§f: §b✆ §f§rBring me that §aEnchanted Dandelion §fas soon as you can!
// */
// private val patterns by RepoPattern.list(
// "crimson.pablo.helper",
// "\\[NPC] Pablo: (?:✆ )?Could you bring me an (?<flower>[\\w ]+).*",
// "\\[NPC] Pablo: (?:✆ )?Bring me that (?<flower>[\\w ]+) as soon as you can!",
// )
private val patterns = listOf(
"\\[NPC] Pablo: (?:✆ )?Are you available\\? I desperately need an? (?<flower>[\\w ]+) today\\.".toPattern(),
"\\[NPC] Pablo: (?:✆ )?Bring me that (?<flower>[\\w ]+) as soon as you can!".toPattern(),
"\\[NPC] Pablo: (?:✆ )?Could you bring me an? (?<flower>[\\w ]+)\\?".toPattern(),
"\\[NPC] Pablo: (?:✆ )?I really need an? (?<flower>[\\w ]+) today, do you have one you could spare\\?".toPattern(),
)
private var lastSentMessage = SimpleTimeMark.farPast()
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!isEnabled()) return
if (lastSentMessage.passedSince() < 5.minutes) return
val itemName = patterns.matchMatchers(event.message.removeColor()) {
group("flower")
} ?: return
if (InventoryUtils.countItemsInLowerInventory { it.name.contains(itemName) } > 0) return
DelayedRun.runNextTick {
GetFromSackAPI.getFromChatMessageSackItems(
itemName.asInternalName().makePrimitiveStack(),
"Click here to grab an $itemName from sacks!",
)
}
lastSentMessage = SimpleTimeMark.now()
}
fun isEnabled() = LorenzUtils.inSkyBlock && config.pabloHelper
}