diff options
| author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-17 11:52:51 +0100 |
|---|---|---|
| committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-17 11:52:51 +0100 |
| commit | 18e96e6c3b867da06aabd29bcd83e92ffe58a00e (patch) | |
| tree | 7ac50db2fa25e0dbb1c91e0f94b9b18974efd122 /src/main/java/at/hannibal2/skyhanni/features/misc | |
| parent | 3468dcc7df5d93157dd16d0a9b6d6ddbd736a5a0 (diff) | |
| download | skyhanni-18e96e6c3b867da06aabd29bcd83e92ffe58a00e.tar.gz skyhanni-18e96e6c3b867da06aabd29bcd83e92ffe58a00e.tar.bz2 skyhanni-18e96e6c3b867da06aabd29bcd83e92ffe58a00e.zip | |
Created PetAPI and deprecated String.matchRegex()
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt | 49 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt | 4 |
2 files changed, 26 insertions, 27 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt index fe9d55176..7855a94b9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt @@ -2,53 +2,53 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.features.rift.RiftAPI import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.between import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.matchRegex +import at.hannibal2.skyhanni.utils.StringUtils.matches import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class CurrentPetDisplay { + private val config get() = SkyHanniMod.feature.misc.pets // TODO USE SH-REPO private val inventoryNamePattern = "(?:\\(\\d+/\\d+\\))? Pets".toPattern() + private val chatSpawnPattern = "§aYou summoned your §r(?<pet>.*)§r§a!".toPattern() + private val chatDespawnPattern = "§aYou despawned your §r.*§r§a!".toPattern() + private val chatPetRulePattern = "§cAutopet §eequipped your §7\\[Lvl .*] (?<pet>.*)! §a§lVIEW RULE".toPattern() @SubscribeEvent fun onChatMessage(event: LorenzChatEvent) { - val message = event.message - val config = ProfileStorageData.profileSpecific ?: return - var blocked = false - if (message.matchRegex("§cAutopet §eequipped your §7(.*)§e! §a§lVIEW RULE")) { - config.currentPet = message.between("] ", "§e!") - blocked = true + findPetInChat(event.message)?.let { + PetAPI.currentPet = it + if (config.display) { + event.blockedReason = "pets" + } } + } - if (!LorenzUtils.inSkyBlock) return - - if (message.matchRegex("§aYou summoned your §r(.*)§r§a!")) { - config.currentPet = message.between("your §r", "§r§a") - blocked = true + private fun findPetInChat(message: String): String? { + chatSpawnPattern.matchMatcher(message) { + return group("pet") } - if (message.matchRegex("§aYou despawned your §r(.*)§r§a!")) { - config.currentPet = "" - blocked = true + if (chatDespawnPattern.matches(message)) { + return "" } - - if (blocked && SkyHanniMod.feature.misc.pets.display) { - event.blockedReason = "pets" + chatPetRulePattern.matchMatcher(message) { + return group("pet") } + + return null } @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { - val storage = ProfileStorageData.profileSpecific ?: return if (!inventoryNamePattern.matcher(event.inventoryName).matches()) return val lore = event.inventoryItems[4]?.getLore() ?: return @@ -56,7 +56,7 @@ class CurrentPetDisplay { for (line in lore) { selectedPetPattern.matchMatcher(line) { val newPet = group("pet") - storage.currentPet = if (newPet != "§cNone") newPet else "" + PetAPI.currentPet = if (newPet != "§cNone") newPet else "" } } } @@ -66,10 +66,9 @@ class CurrentPetDisplay { if (!LorenzUtils.inSkyBlock) return if (RiftAPI.inRift()) return - if (!SkyHanniMod.feature.misc.pets.display) return - val storage = ProfileStorageData.profileSpecific ?: return + if (!config.display) return - SkyHanniMod.feature.misc.pets.displayPos.renderString(storage.currentPet, posLabel = "Current Pet") + config.displayPos.renderString(PetAPI.currentPet, posLabel = "Current Pet") } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt index 9937ff288..e95132ff7 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt @@ -10,7 +10,7 @@ import at.hannibal2.skyhanni.data.GardenCropMilestones.isMaxed import at.hannibal2.skyhanni.data.GardenCropMilestones.progressToNextLevel import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType @@ -289,7 +289,7 @@ enum class DiscordStatus(private val displayMessageSupplier: Supplier<String>?) }), PETS({ - ProfileStorageData.profileSpecific?.currentPet?.let { + PetAPI.currentPet?.let { val colorCode = it.substring(1..2).first() val petName = it.substring(2) val petLevel = getCurrentPet()?.petLevel?.currentLevel ?: "?" |
