aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-17 11:52:51 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-17 11:52:51 +0100
commit18e96e6c3b867da06aabd29bcd83e92ffe58a00e (patch)
tree7ac50db2fa25e0dbb1c91e0f94b9b18974efd122 /src/main/java
parent3468dcc7df5d93157dd16d0a9b6d6ddbd736a5a0 (diff)
downloadskyhanni-18e96e6c3b867da06aabd29bcd83e92ffe58a00e.tar.gz
skyhanni-18e96e6c3b867da06aabd29bcd83e92ffe58a00e.tar.bz2
skyhanni-18e96e6c3b867da06aabd29bcd83e92ffe58a00e.zip
Created PetAPI and deprecated String.matchRegex()
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/CurrentPetDisplay.kt49
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordStatus.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt1
6 files changed, 42 insertions, 39 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
new file mode 100644
index 000000000..c21b2f384
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt
@@ -0,0 +1,10 @@
+package at.hannibal2.skyhanni.data
+
+object PetAPI {
+
+ var currentPet: String?
+ get() = ProfileStorageData.profileSpecific?.currentPet
+ set(value) {
+ ProfileStorageData.profileSpecific?.currentPet = value
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt
index 28cc33e1b..a9806ab2f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/DianaAPI.kt
@@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.event.diana
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.MayorElection
-import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.data.PetAPI
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
@@ -17,7 +17,7 @@ object DianaAPI {
private fun isRitualActive() = MayorElection.isPerkActive("Diana", "Mythological Ritual") ||
MayorElection.isPerkActive("Jerry", "Perkpocalypse") || SkyHanniMod.feature.event.diana.alwaysDiana
- fun hasGriffinPet() = ProfileStorageData.profileSpecific?.currentPet?.contains("Griffin") ?: false
+ fun hasGriffinPet() = PetAPI.currentPet?.contains("Griffin") ?: false
fun featuresEnabled() = IslandType.HUB.isInIsland() && isRitualActive()
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
index 22f897a4c..5dd1804cc 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
@@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.data.PetAPI
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.events.BlockClickEvent
import at.hannibal2.skyhanni.events.ConfigLoadEvent
@@ -12,7 +13,6 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
-import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType
import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay
import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI
@@ -46,7 +46,7 @@ object GardenAPI {
var toolInHand: String? = null
var itemInHand: ItemStack? = null
var cropInHand: CropType? = null
- var mushroomCowPet = false
+ val mushroomCowPet get() = PetAPI.currentPet?.contains("Mushroom Cow") ?: false
private var inBarn = false
val onBarnPlot get() = inBarn && inGarden()
val storage get() = ProfileStorageData.profileSpecific?.garden
@@ -86,13 +86,6 @@ object GardenAPI {
}
@SubscribeEvent
- fun onTabListUpdate(event: TabListUpdateEvent) {
- if (inGarden()) {
- mushroomCowPet = event.tabList.any { it.startsWith(" Strength: §r§c❁") }
- }
- }
-
- @SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
SkyHanniMod.coroutineScope.launch {
delay(2.seconds)
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 ?: "?"
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index b60c08b6f..05694c0a9 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -71,6 +71,7 @@ object StringUtils {
return toString().replace("-", "")
}
+ @Deprecated("Do not create a regex pattern each time.", ReplaceWith("toPattern()"))
fun String.matchRegex(@Language("RegExp") regex: String): Boolean = regex.toRegex().matches(this)
private fun String.removeAtBeginning(text: String): String =