Skip to content

Commit

Permalink
more files
Browse files Browse the repository at this point in the history
  • Loading branch information
catgirlseraid committed May 22, 2024
1 parent 385e184 commit 8a683bc
Show file tree
Hide file tree
Showing 24 changed files with 203 additions and 112 deletions.
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/MaxwellAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ object MaxwellAPI {
"gui.noselectedpower",
"(?:§.)*Visit Maxwell in the Hub to learn"
)
private val accessoryBagStack by patternGroup.pattern(
private val accessoryBagStackPattern by patternGroup.pattern(
"stack.accessorybag",
"§.Accessory Bag"
)
Expand Down Expand Up @@ -164,7 +164,7 @@ object MaxwellAPI {

if (yourBagsGuiPattern.matches(event.inventoryName)) {
for (stack in event.inventoryItems.values) {
if (accessoryBagStack.matches(stack.displayName)) processStack(stack)
if (accessoryBagStackPattern.matches(stack.displayName)) processStack(stack)
}
}
if (statsTuningGuiPattern.matches(event.inventoryName)) {
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ object PetAPI {
"menu.title",
"Pets(?: \\(\\d+/\\d+\\) )?"
)
private val petItemName by patternGroup.pattern(
private val petItemNamePattern by patternGroup.pattern(
"item.name",
"(?:§.)*\\[Lvl (?<level>\\d+)] (?<name>.*)"
)
private val neuRepoPetItemName by patternGroup.pattern(
private val neuRepoPetItemNamePattern by patternGroup.pattern(
"item.name.neu.format",
"(§f§f)?§7\\[Lvl 1➡(100|200)] (?<name>.*)"
)
Expand All @@ -40,19 +40,20 @@ object PetAPI {
fun isCurrentPet(petName: String): Boolean = currentPet?.contains(petName) ?: false

fun getCleanName(nameWithLevel: String): String? {
petItemName.matchMatcher(nameWithLevel) {
petItemNamePattern.matchMatcher(nameWithLevel) {
return group("name")
}
neuRepoPetItemName.matchMatcher(nameWithLevel) {
neuRepoPetItemNamePattern.matchMatcher(nameWithLevel) {
return group("name")
}

return null
}

fun getPetLevel(nameWithLevel: String): Int? = petItemName.matchMatcher(nameWithLevel) {
fun getPetLevel(nameWithLevel: String): Int? = petItemNamePattern.matchMatcher(nameWithLevel) {
group("level").toInt()
}

fun hasPetName(name: String): Boolean = petItemName.matches(name) && !ignoredPetStrings.any { name.contains(it) }
fun hasPetName(name: String): Boolean =
petItemNamePattern.matches(name) && !ignoredPetStrings.any { name.contains(it) }
}
22 changes: 14 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/data/SackAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
import at.hannibal2.skyhanni.utils.StringUtils.findMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matchAll
import at.hannibal2.skyhanni.utils.StringUtils.matchFirst
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
Expand Down Expand Up @@ -57,6 +58,10 @@ object SackAPI {
"gemstone",
" §[0-9a-f](?<gemrarity>[A-z]*): §[0-9a-f](?<stored>\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?)(?: §[0-9a-f]\\(\\d+(?:\\.\\d+)?(?:(?:,\\d+)?)+[kKmM]?\\))?"
)
private val sackChangePattern by patternGroup.pattern(
"sackchange",
"(?<amount>[+-][\\d,]+) (?<item>.+) \\((?<sacks>.+)\\)"
)

private var isRuneSack = false
private var isGemstoneSack = false
Expand Down Expand Up @@ -228,8 +233,6 @@ object SackAPI {

data class SackChange(val delta: Int, val internalName: NEUInternalName, val sacks: List<String>)

private val sackChangeRegex = Regex("""([+-][\d,]+) (.+) \((.+)\)""")

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!event.message.removeColor().startsWith("[Sacks]")) return
Expand All @@ -252,13 +255,16 @@ object SackAPI {
val otherItemsRemoved = sackRemoveText.contains("other items")

val sackChanges = ArrayList<SackChange>()
for (match in sackChangeRegex.findAll(sackChangeText)) {
val delta = match.groups[1]!!.value.formatInt()
val item = match.groups[2]!!.value
val sacks = match.groups[3]!!.value.split(", ")

val internalName = NEUInternalName.fromItemName(item)
sackChanges.add(SackChange(delta, internalName, sacks))
for (line in sackChangeText.lines()) {
sackChangePattern.findMatcher(line) {
val amount = group("amount").formatInt()
val item = group("name")
val sacks = group("sacks").split(", ")

val internalName = NEUInternalName.fromItemName(item)
sackChanges.add(SackChange(amount, internalName, sacks))
}
}
val sackEvent = SackChangeEvent(sackChanges, otherItemsAdded, otherItemsRemoved)
updateSacks(sackEvent)
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/at/hannibal2/skyhanni/data/mob/MobDetection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ class MobDetection {
private var shouldClear: AtomicBoolean = AtomicBoolean(false)

init {
MobFilter.bossMobNameFilter
MobFilter.mobNameFilter
MobFilter.dojoFilter
MobFilter.summonFilter
MobFilter.dungeonNameFilter
MobFilter.bossMobNamePattern
MobFilter.mobNamePattern
MobFilter.dojoPattern
MobFilter.summonPattern
MobFilter.dungeonNamePattern
MobFilter.petCareNamePattern
MobFilter.slayerNameFilter
MobFilter.slayerNamePattern
MobFilter.summonOwnerPattern
MobFilter.wokeSleepingGolemPattern
MobFilter.jerryPattern
MobFilter.jerryMagmaCubePattern
MobUtils.defaultArmorStandName
MobUtils.defaultArmorStandNamePattern
}

private fun mobDetectionReset() {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/data/mob/MobFactories.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object MobFactories {
armorStand: EntityArmorStand,
extraEntityList: List<EntityLivingBase>
): Mob? =
MobFilter.slayerNameFilter.findMatcher(armorStand.cleanName()) {
MobFilter.slayerNamePattern.findMatcher(armorStand.cleanName()) {
Mob(
baseEntity = baseEntity,
mobType = Mob.Type.SLAYER,
Expand All @@ -31,7 +31,7 @@ object MobFactories {
extraEntityList: List<EntityLivingBase> = emptyList(),
overriddenName: String? = null
): Mob? =
MobFilter.bossMobNameFilter.matchMatcher(armorStand.cleanName()) {
MobFilter.bossMobNamePattern.matchMatcher(armorStand.cleanName()) {
Mob(
baseEntity = baseEntity,
mobType = Mob.Type.BOSS,
Expand All @@ -47,7 +47,7 @@ object MobFactories {
armorStand: EntityArmorStand,
extraEntityList: List<EntityLivingBase> = emptyList()
): Mob? =
MobFilter.dungeonNameFilter.matchMatcher(armorStand.cleanName()) {
MobFilter.dungeonNamePattern.matchMatcher(armorStand.cleanName()) {
Mob(
baseEntity = baseEntity,
mobType = Mob.Type.DUNGEON,
Expand All @@ -67,7 +67,7 @@ object MobFactories {
armorStand: EntityArmorStand,
extraEntityList: List<EntityLivingBase>? = null
): Mob? =
MobFilter.mobNameFilter.findMatcher(armorStand.cleanName()) {
MobFilter.mobNamePattern.findMatcher(armorStand.cleanName()) {
Mob(
baseEntity = baseEntity,
mobType = Mob.Type.BASIC,
Expand All @@ -89,7 +89,7 @@ object MobFactories {
armorStand: EntityArmorStand,
extraEntityList: List<EntityLivingBase>
): Mob? =
MobFilter.summonFilter.findMatcher(armorStand.cleanName()) {
MobFilter.summonPattern.findMatcher(armorStand.cleanName()) {
Mob(
baseEntity = baseEntity,
mobType = Mob.Type.SUMMON,
Expand Down Expand Up @@ -118,7 +118,7 @@ object MobFactories {

private fun String.removeCorruptedSuffix(case: Boolean) = if (case) this.dropLast(1) else this
fun dojo(baseEntity: EntityLivingBase, armorStand: EntityArmorStand): Mob? =
MobFilter.dojoFilter.matchMatcher(armorStand.cleanName()) {
MobFilter.dojoPattern.matchMatcher(armorStand.cleanName()) {
Mob(
baseEntity = baseEntity,
mobType = Mob.Type.SPECIAL,
Expand Down
52 changes: 36 additions & 16 deletions src/main/java/at/hannibal2/skyhanni/data/mob/MobFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ import net.minecraft.entity.player.EntityPlayer
@Suppress("RegExpRedundantEscape")
object MobFilter {

private val repoGroup = RepoPattern.group("mob.detection.new")
private val patternGroup = RepoPattern.group("mob.detection.new")

/** REGEX-TEST: Wither Husk 500M❤ */
val mobNameFilter by repoGroup.pattern(
val mobNamePattern by patternGroup.pattern(
"filter.basic",
"(?:\\[\\w+(?<level>\\d+)\\] )?(?<corrupted>.Corrupted )?(?<name>[^ᛤ]*)(?: ᛤ)? [\\dBMk.,❤]+"
)
val slayerNameFilter by repoGroup.pattern("filter.slayer", "^. (?<name>.*) (?<tier>[IV]+) \\d+")
val slayerNamePattern by patternGroup.pattern(
"filter.slayer",
"^. (?<name>.*) (?<tier>[IV]+) \\d+"
)

/** REGEX-TEST: ﴾ Storm ﴿
* REGEX-TEST: ﴾ [Lv200] aMage Outlawa 70M/70M❤ ﴿
Expand All @@ -65,28 +68,46 @@ object MobFilter {
* REGEX-TEST: ﴾ [Lv200] Barbarian Duke X 70M/70M❤ ﴿
* REGEX-TEST: ﴾ [Lv100] Endstone Protector 4.6M/5M❤ ﴿
* */
val bossMobNameFilter by repoGroup.pattern(
val bossMobNamePattern by patternGroup.pattern(
"filter.boss",
"^. (?:\\[Lv(?<level>\\d+)\\] )?(?<name>[^ᛤ\n]*)(?: ᛤ)?(?: [\\d\\/BMk.,❤]+|█+)? .$"
)
val dungeonNameFilter by repoGroup.pattern(
val dungeonNamePattern by patternGroup.pattern(
"filter.dungeon",
"^(?:(?<star>✯)\\s)?(?:(?<attribute>${DungeonAttribute.toRegexLine})\\s)?(?:\\[[\\w\\d]+\\]\\s)?(?<name>[^ᛤ]+)(?: ᛤ)?\\s[^\\s]+$"
)
val summonFilter by repoGroup.pattern("filter.summon", "^(?<owner>\\w+)'s (?<name>.*) \\d+")
val dojoFilter by repoGroup.pattern("filter.dojo", "^(?:(?<points>\\d+) pts|(?<empty>\\w+))$")
val jerryPattern by repoGroup.pattern(
val summonPattern by patternGroup.pattern(
"filter.summon",
"^(?<owner>\\w+)'s (?<name>.*) \\d+"
)
val dojoPattern by patternGroup.pattern(
"filter.dojo",
"^(?:(?<points>\\d+) pts|(?<empty>\\w+))$"
)
val jerryPattern by patternGroup.pattern(
"jerry",
"(?:\\[\\w+(?<level>\\d+)\\] )?(?<owner>\\w+)'s (?<name>\\w+ Jerry) \\d+ Hits"
)

val petCareNamePattern by repoGroup.pattern("pattern.petcare", "^\\[\\w+ (?<level>\\d+)\\] (?<name>.*)")
val wokeSleepingGolemPattern by repoGroup.pattern("pattern.dungeon.woke.golem", "(?:§c§lWoke|§5§lSleeping) Golem§r")
val jerryMagmaCubePattern by repoGroup.pattern(
val petCareNamePattern by patternGroup.pattern(
"pattern.petcare",
"^\\[\\w+ (?<level>\\d+)\\] (?<name>.*)"
)
val wokeSleepingGolemPattern by patternGroup.pattern(
"pattern.dungeon.woke.golem",
"(?:§c§lWoke|§5§lSleeping) Golem§r"
)
val jerryMagmaCubePattern by patternGroup.pattern(
"pattern.jerry.magma.cube",
"§c(?:Cubie|Maggie|Cubert|Cübe|Cubette|Magmalene|Lucky 7|8ball|Mega Cube|Super Cube)(?: ᛤ)? §a\\d+§8\\/§a\\d+§c❤"
)
val summonOwnerPattern by repoGroup.pattern("pattern.summon.owner", "Spawned by: (?<name>.*)")
val summonOwnerPattern by patternGroup.pattern(
"pattern.summon.owner",
"Spawned by: (?<name>.*)"
)
val isGuardianPattern by patternGroup.pattern(
"isgaurdian",
"^\\d+"
)

internal const val RAT_SKULL =
"ewogICJ0aW1lc3RhbXAiIDogMTYxODQxOTcwMTc1MywKICAicHJvZmlsZUlkIiA6ICI3MzgyZGRmYmU0ODU0NTVjODI1ZjkwMGY4OGZkMzJmOCIsCiAgInByb2ZpbGVOYW1lIiA6ICJCdUlJZXQiLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYThhYmI0NzFkYjBhYjc4NzAzMDExOTc5ZGM4YjQwNzk4YTk0MWYzYTRkZWMzZWM2MWNiZWVjMmFmOGNmZmU4IiwKICAgICAgIm1ldGFkYXRhIiA6IHsKICAgICAgICAibW9kZWwiIDogInNsaW0iCiAgICAgIH0KICAgIH0KICB9Cn0="
Expand Down Expand Up @@ -125,7 +146,7 @@ object MobFilter {
"anrrtqytsl", // Weaponsmith
)

private val displayNPCCompressedNamePattern by repoGroup.pattern("displaynpc.name", "[a-z0-9]{10}")
private val displayNPCCompressedNamePattern by patternGroup.pattern("displaynpc.name", "[a-z0-9]{10}")

private fun displayNPCNameCheck(name: String) = name.startsWith('§')
|| displayNPCCompressedNamePattern.matches(name)
Expand Down Expand Up @@ -287,8 +308,7 @@ object MobFilter {

baseEntity is EntityHorse && armorStand.name.endsWith("'s Horse") -> MobResult.illegal // Horse Pet

baseEntity is EntityGuardian && armorStand.cleanName()
.matches("^\\d+".toRegex()) -> MobResult.illegal // Wierd Sea Guardian Ability
baseEntity is EntityGuardian && isGuardianPattern.matches(armorStand.cleanName()) -> MobResult.illegal // Wierd Sea Guardian Ability

else -> null
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/features/chat/Translator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ConditionalUtils.transformIf
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils.findMatcher
import at.hannibal2.skyhanni.utils.StringUtils.getPlayerNameFromChatMessage
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.gson.JsonArray
import kotlinx.coroutines.launch
import net.minecraft.event.ClickEvent
Expand All @@ -23,7 +25,12 @@ import java.net.URLEncoder
// TODO split into two classes: TranslatorCommand and GoogleTransaltor. only communicates via getTranslationFromEnglish and getTranslationToEnglish
class Translator {

private val messageContentRegex = Regex(".*: (.*)")
private val patternGroup = RepoPattern.group("translator")
private val messageContentPattern by patternGroup.pattern(
"messagecontent",
".*: (?<content>.*)"
)


// Logic for listening for a user click on a chat message is from NotEnoughUpdates

Expand All @@ -43,7 +50,10 @@ class Translator {
}

private fun createClickStyle(message: String, style: ChatStyle): ChatStyle {
val text = messageContentRegex.find(message)!!.groupValues[1].removeColor()
//TODO seraid
val text = messageContentPattern.findMatcher(message) {
group("content").removeColor()
}
style.setChatClickEvent(ClickEvent(ClickEvent.Action.RUN_COMMAND, "/shtranslate $text"))
style.setChatHoverEvent(HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("§bClick to translate!")))
return style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.toRoman
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.StringUtils.find
import at.hannibal2.skyhanni.utils.StringUtils.findMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
Expand Down Expand Up @@ -110,6 +111,22 @@ object BestiaryData {
"results",
"^§7Results: §a"
)
private val namePattern by patternGroup.pattern(
"name",
" [IVX0-9]+$"
)
private val levelPattern by patternGroup.pattern(
"level",
" (?<level>[IVX0-9]+$)"
)
private val spacePattern by patternGroup.pattern(
"space",
"^ {20}"
)
private val actualRealTotalKillPattern by patternGroup.pattern(
"actualrealtotalkill",
"(?<kills>[0-9,.]+)"
)

private var display = emptyList<List<Any>>()
private val mobList = mutableListOf<BestiaryMob>()
Expand Down Expand Up @@ -211,7 +228,7 @@ object BestiaryData {
var familiesCompleted: Long = 0
for ((lineIndex, loreLine) in stack.getLore().withIndex()) {
val line = loreLine.removeColor()
if (!line.startsWith(" ")) continue
if (!spacePattern.find(loreLine)) continue
val previousLine = stack.getLore()[lineIndex - 1]
val progress = line.substring(line.lastIndexOf(' ') + 1)
if (familiesFoundContainsPattern.find(previousLine)) {
Expand All @@ -235,8 +252,10 @@ object BestiaryData {
if (stack.displayName == " ") continue
if (!indexes.contains(index)) continue
inInventory = true
val name = " [IVX0-9]+$".toPattern().matcher(stack.displayName).replaceFirst("")
val level = " ([IVX0-9]+$)".toRegex().find(stack.displayName)?.groupValues?.get(1) ?: "0"
val name = namePattern.matcher(stack.displayName).replaceFirst("")
val level = levelPattern.findMatcher(stack.displayName) {
group("level")
} ?: "0"
var totalKillToMax: Long = 0
var currentTotalKill: Long = 0
var totalKillToTier: Long = 0
Expand All @@ -245,8 +264,9 @@ object BestiaryData {
for ((lineIndex, line) in stack.getLore().withIndex()) {
val loreLine = line.removeColor()
if (killsPattern.find(loreLine)) {
actualRealTotalKill = "([0-9,.]+)".toRegex().find(loreLine)?.groupValues?.get(1)?.formatLong()
?: 0
actualRealTotalKill = actualRealTotalKillPattern.findMatcher(loreLine) {
group("kills").formatLong()
} ?: 0
}
if (!loreLine.startsWith(" ")) continue
val previousLine = stack.getLore()[lineIndex - 1]
Expand Down
Loading

0 comments on commit 8a683bc

Please sign in to comment.