Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed Nov 1, 2024
1 parent dc3fa0d commit 138734d
Showing 1 changed file with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.network.play.server.S02PacketChat
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Matcher
import java.util.regex.Pattern
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
Expand All @@ -46,7 +47,7 @@ object InquisitorWaypointShare {
*/
private val partyOnlyCoordsPattern by patternGroup.pattern(
"party.onlycoords",
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rx: (?<x>[^ ,]+),? y: (?<y>[^ ,]+),? z: (?<z>[^ ,]+)"
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rx: (?<x>[^ ,]+),? y: (?<y>[^ ,]+),? z: (?<z>[^ ,]+)",
)

// Support for https://www.chattriggers.com/modules/v/inquisitorchecker
Expand All @@ -56,7 +57,7 @@ object InquisitorWaypointShare {
@Suppress("MaxLineLength")
private val partyInquisitorCheckerPattern by patternGroup.pattern(
"party.inquisitorchecker",
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rA MINOS INQUISITOR has spawned near \\[(?<area>.*)] at Coords (?<x>[^ ]+) (?<y>[^ ]+) (?<z>[^ ]+)"
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rA MINOS INQUISITOR has spawned near \\[(?<area>.*)] at Coords (?<x>[^ ]+) (?<y>[^ ]+) (?<z>[^ ]+)",
)

/**
Expand All @@ -65,7 +66,7 @@ object InquisitorWaypointShare {
@Suppress("MaxLineLength")
private val odinPattern by patternGroup.pattern(
"party.odin",
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rx: (?<x>[^ ]+), y: (?<y>[^ ]+), z: (?<z>[^ ]+) I dug up an inquisitor come over here!"
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rx: (?<x>[^ ]+), y: (?<y>[^ ]+), z: (?<z>[^ ]+) I dug up an inquisitor come over here!",
)

/**
Expand All @@ -74,20 +75,20 @@ object InquisitorWaypointShare {
@Suppress("MaxLineLength")
private val sboPattern by patternGroup.pattern(
"party.sbo",
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rx: (?<x>[^ ]+), y: (?<y>[^ ]+), z: (?<z>[^ ]+) \\| Minos Inquisitor spawned at (?<area>.*)!"
"(?<party>§9Party §8> )?(?<playerName>.+)§f: §rx: (?<x>[^ ]+), y: (?<y>[^ ]+), z: (?<z>[^ ]+) \\| Minos Inquisitor spawned at (?<area>.*)!",
)

private val diedPattern by patternGroup.pattern(
"died",
"(?<party>§9Party §8> )?(?<playerName>.*)§f: §rInquisitor dead!"
"(?<party>§9Party §8> )?(?<playerName>.*)§f: §rInquisitor dead!",
)

/**
* REGEX-TEST: §c§lUh oh! §r§eYou dug out a §r§2Minos Inquisitor§r§e!
*/
private val inquisitorFoundChatPattern by patternGroup.pattern(
"inquisitor.dug",
".* §r§eYou dug out a §r§2Minos Inquisitor§r§e!"
".* §r§eYou dug out a §r§2Minos Inquisitor§r§e!",
)

private var inquisitor = -1
Expand Down Expand Up @@ -175,11 +176,12 @@ object InquisitorWaypointShare {
val keyName = KeyboardManager.getKeyName(config.keyBindShare)
val message = "§l§bYou found an Inquisitor! Click §l§chere §l§bor press §c$keyName to share the location!"
ChatUtils.clickableChat(
message, onClick = {
message,
onClick = {
sendInquisitor()
},
"§eClick to share!",
oneTimeClick = true
oneTimeClick = true,
)
}
}
Expand Down Expand Up @@ -256,21 +258,17 @@ object InquisitorWaypointShare {
//$$ if (packet.type.id.toInt() != 0) return
//#endif

partyInquisitorCheckerPattern.matchMatcher(message) {
if (detectFromChat()) {
event.cancel()
}
if (partyInquisitorCheckerPattern.isDetected(message)) {
event.cancel()
}
odinPattern.matchMatcher(message) {
if (detectFromChat()) {
event.cancel()
}
if (odinPattern.isDetected(message)) {
event.cancel()
}

partyOnlyCoordsPattern.matchMatcher(message) {
if (detectFromChat()) {
event.cancel()
}
if (partyOnlyCoordsPattern.isDetected(message)) {
event.cancel()
}
if (sboPattern.isDetected(message)) {
event.cancel()
}
diedPattern.matchMatcher(message) {
if (block()) return
Expand All @@ -281,6 +279,10 @@ object InquisitorWaypointShare {
}
}

private fun Pattern.isDetected(message: String): Boolean = matchMatcher(message) {
detectFromChat()
} ?: false

private fun Matcher.block(): Boolean = !hasGroup("party") && !config.globalChat

private fun Matcher.detectFromChat(): Boolean {
Expand Down

0 comments on commit 138734d

Please sign in to comment.